diff options
Diffstat (limited to 'hw/xwin')
40 files changed, 2512 insertions, 2412 deletions
diff --git a/hw/xwin/InitInput.c b/hw/xwin/InitInput.c index a9f69aad5..de84a7aee 100644 --- a/hw/xwin/InitInput.c +++ b/hw/xwin/InitInput.c @@ -26,9 +26,10 @@ from The Open Group. */ -/* $XFree86: xc/programs/Xserver/hw/xwin/InitInput.c,v 1.12 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/InitInput.c,v 1.13 2003/07/29 21:25:15 dawes Exp $ */ #include "win.h" +#include "../../Xext/xf86miscproc.h" CARD32 g_c32LastInputEventTime = 0; @@ -117,6 +118,34 @@ 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"); #endif diff --git a/hw/xwin/InitOutput.c b/hw/xwin/InitOutput.c index c434e58d1..3202ae8d9 100644 --- a/hw/xwin/InitOutput.c +++ b/hw/xwin/InitOutput.c @@ -26,11 +26,11 @@ other dealings in this Software without prior written authorization from The Open Group. */ -/* $XFree86: xc/programs/Xserver/hw/xwin/InitOutput.c,v 1.32 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/InitOutput.c,v 1.35 2003/10/08 11:13:02 eich Exp $ */ #include "win.h" #include "winconfig.h" - +#include "winprefs.h" /* * General global variables @@ -47,11 +47,16 @@ int g_iPixmapPrivateIndex = -1; int g_iWindowPrivateIndex = -1; unsigned long g_ulServerGeneration = 0; Bool g_fInitializedDefaultScreens = FALSE; -FILE *g_pfLog = NULL; 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; /* @@ -151,6 +156,7 @@ winInitializeDefaultScreens (void) 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; @@ -177,6 +183,10 @@ ddxGiveUp() ErrorF ("ddxGiveUp\n"); #endif + /* Notify the worker threads we're exiting */ + winDeinitClipboard (); + winDeinitMultiWindowWM (); + /* Close our handle to our message queue */ if (g_fdMessageQueue != WIN_FD_INVALID) { @@ -187,15 +197,11 @@ ddxGiveUp() g_fdMessageQueue = WIN_FD_INVALID; } - /* Close the log file handle */ - if (g_pfLog != NULL) - { - /* Close log file */ - fclose (g_pfLog); - - /* Set the file handle to invalid */ - g_pfLog = NULL; - } + if (!g_fLogInited) { + LogInit(g_pszLogFile, NULL); + g_fLogInited = TRUE; + } + LogClose(); /* * At this point we aren't creating any new screens, so @@ -239,12 +245,15 @@ OsVendorInit (void) #ifdef DDXOSVERRORF if (!OsVendorVErrorFProc) OsVendorVErrorFProc = OsVendorVErrorF; - - /* Open log file if not yet open */ - if (g_pfLog == NULL) - g_pfLog = fopen (WIN_LOG_FNAME, "w"); #endif + if (!g_fLogInited) { + LogInit(g_pszLogFile, NULL); + g_fLogInited = TRUE; + } + LogSetParameter(XLOG_FLUSH, 1); + LogSetParameter(XLOG_VERBOSITY, g_iLogVerbose); + /* Add a default screen if no screens were specified */ if (g_iNumScreens == 0) { @@ -328,6 +337,12 @@ ddxUseMsg (void) "\tMoreover, if the window has decorations, one can now resize\n" "\tit.\n"); + ErrorF ("-[no]trayicon\n" + "\tDo not create a tray icon. Default is to create one\n" + "\ticon per screen. You can globally disable tray icons with\n" + "\t-notrayicon, then enable it for specific screens with\n" + "\t-trayicon for those screens.\n"); + ErrorF ("-clipupdates num_boxes\n" "\tUse a clipping region to constrain shadow update blits to\n" "\tthe updated region when num_boxes, or more, are in the\n" @@ -393,10 +408,6 @@ ddxProcessArgument (int argc, char *argv[], int i) * that are generated before OsInit () is called. */ OsVendorVErrorFProc = OsVendorVErrorF; - - /* Open log file if not yet open */ - if (g_pfLog == NULL) - g_pfLog = fopen (WIN_LOG_FNAME, "w"); #endif s_fBeenHere = TRUE; @@ -761,6 +772,8 @@ ddxProcessArgument (int argc, char *argv[], int i) return 1; } + + /* * Look for the '-clipboard' argument */ @@ -1106,6 +1119,58 @@ ddxProcessArgument (int argc, char *argv[], int i) } /* + * 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; + + /* 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; + } + + /* * Look for the '-fp' argument */ if (IS_OPTION ("-fp")) @@ -1126,6 +1191,16 @@ ddxProcessArgument (int argc, char *argv[], int i) } /* + * Look for the '-query' argument + */ + if (IS_OPTION ("-query")) + { + CHECK_ARGS (1); + g_pszQueryHost = argv[++i]; + return 0; /* Let DIX parse this again */ + } + + /* * Look for the '-xf86config' argument */ if (IS_OPTION ("-xf86config")) @@ -1145,6 +1220,26 @@ ddxProcessArgument (int argc, char *argv[], int i) 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; + } + return 0; } @@ -1255,6 +1350,8 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[]) } } + LoadPreferences(); + #if CYGDEBUG || YES ErrorF ("InitOutput - Returning.\n"); #endif diff --git a/hw/xwin/XWin.man b/hw/xwin/XWin.man index 09bdcd235..fe78047c4 100644 --- a/hw/xwin/XWin.man +++ b/hw/xwin/XWin.man @@ -1,4 +1,4 @@ -.\" $XFree86: xc/programs/Xserver/hw/xwin/XWin.man,v 1.6 2002/10/17 08:18:21 alanh Exp $ +.\" $XFree86: xc/programs/Xserver/hw/xwin/XWin.man,v 1.7 2003/10/02 13:30:09 eich Exp $ .TH XWIN 1 __vendorversion__ .SH NAME XWin \- X Server for the Cygwin environment on Microsoft Windows @@ -87,7 +87,7 @@ Ctrl+Alt+Backspace exits the X Server Alt+F4 exits the X Server .SH "SEE ALSO" .PP -X(__miscmansuffix__), Xserver(1), xdm(1), xinit(1) +X(__miscmansuffix__), Xserver(1), xdm(1), xinit(1), XWinrc(5) .SH BUGS .I XWin and this man page still have many limitations. Some of the more obvious diff --git a/hw/xwin/XWin.rc b/hw/xwin/XWin.rc index 73533ba4e..7b5708af2 100644 --- a/hw/xwin/XWin.rc +++ b/hw/xwin/XWin.rc @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/XWin.rc,v 1.1 2002/10/17 08:18:21 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/XWin.rc,v 1.2 2003/07/29 21:25:15 dawes Exp $ */ #include "resource.h" @@ -36,8 +36,10 @@ * Dialogs */ +/* Depth_Change */ + DEPTH_CHANGE_BOX DIALOG DISCARDABLE 32, 32, 180, 100 -STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE +STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | DS_CENTER FONT 8, "MS Sans Serif" CAPTION "Cygwin/XFree86" BEGIN @@ -48,10 +50,35 @@ BEGIN END +/* Exit */ + +EXIT_DIALOG DIALOG DISCARDABLE 32, 32, 180, 70 +STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_VISIBLE | WS_TABSTOP | DS_CENTER +FONT 8, "MS Sans Serif" +CAPTION "Cygwin/XFree86 - Exit?" +BEGIN + PUSHBUTTON "E&xit", IDOK, 55, 48, 30, 14 + DEFPUSHBUTTON "&Cancel", IDCANCEL, 95, 48, 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 +END + + /* * Menus */ +IDM_TRAYICON_MENU MENU DISCARDABLE +BEGIN + POPUP "TRAYICON_MENU" + BEGIN + MENUITEM "&Hide Root Window", ID_APP_HIDE_ROOT + MENUITEM "&Show Root Window", ID_APP_SHOW_ROOT + MENUITEM SEPARATOR + MENUITEM "E&xit", ID_APP_EXIT + END +END + /* * Icons diff --git a/hw/xwin/win.h b/hw/xwin/win.h index 684e98cc1..6ecf5ada0 100644 --- a/hw/xwin/win.h +++ b/hw/xwin/win.h @@ -31,7 +31,7 @@ * Harold L Hunt II * Kensuke Matsuzaki */ -/* $XFree86: xc/programs/Xserver/hw/xwin/win.h,v 1.34 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/win.h,v 1.38 2003/10/08 11:13:02 eich Exp $ */ #ifndef _WIN_H_ #define _WIN_H_ @@ -93,8 +93,14 @@ | (1 << ( 8 - 1))) #define WIN_CHECK_DEPTH YES +/* + * Timer IDs for WM_TIMER + */ +#define WIN_E3B_TIMER_ID 1 +#define WIN_POLLING_MOUSE_TIMER_ID 2 + + #define WIN_E3B_OFF -1 -#define WIN_E3B_TIMER_ID 1 #define WIN_FD_INVALID -1 #define WIN_SERVER_NONE 0x0L /* 0 */ @@ -144,7 +150,6 @@ #include "pixmapstr.h" #include "pixmap.h" #include "region.h" -#include "regionstr.h" #include "gcstruct.h" #include "colormap.h" #include "colormapst.h" @@ -184,6 +189,15 @@ /* + * Define Windows constants + */ + +#define WM_TRAYICON (WM_USER + 1000) +#define WM_INIT_SYS_MENU (WM_USER + 1001) +#define WM_GIVEUP (WM_USER + 1002) + + +/* * Multi-Window Window Manager header */ @@ -222,7 +236,7 @@ if (fDebugProcMsg) \ #define DEBUG_MSG(str,...) #endif -#if CYGDEBUG || YES +#if CYGDEBUG #define DEBUG_FN_NAME(str) PTSTR szFunctionName = str #else #define DEBUG_FN_NAME(str) @@ -387,6 +401,7 @@ typedef struct Bool fClipboard; Bool fLessPointer; Bool fScrollbars; + Bool fNoTrayIcon; int iE3BTimeout; /* Windows (Alt+F4) and Unix (Ctrl+Alt+Backspace) Killkey */ Bool fUseWinKillKey; @@ -422,6 +437,9 @@ typedef struct _winPrivScreenRec DWORD dwModeKeyStates; + /* Handle to icons that must be freed */ + HICON hiconNotifyIcon; + /* Clipboard support */ pthread_t ptClipboardProc; @@ -482,7 +500,11 @@ typedef struct _winPrivScreenRec /* Privates used by multi-window server */ pthread_t ptWMProc; + pthread_t ptXMsgProc; void *pWMInfo; + Bool fWindowOrderChanged; + Bool fRestacking; + Bool fRootWindowShown; /* Privates used for any module running in a seperate thread */ pthread_mutex_t pmServerStarted; @@ -531,6 +553,12 @@ typedef struct _winPrivScreenRec } winPrivScreenRec; +typedef struct { + pointer value; + XID id; +} WindowIDPairRec, *WindowIDPairPtr; + + /* * Extern declares for general global variables */ @@ -549,6 +577,10 @@ 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; /* @@ -703,6 +735,13 @@ winInitClipboard (pthread_t *ptClipboardProc, pthread_mutex_t *ppmServerStarted, DWORD dwScreen); +/* + * winclipboardthread.c + */ + +void +winDeinitClipboard (); + /* * wincmap.c @@ -772,6 +811,18 @@ winCrossScreen (ScreenPtr pScreen, Bool fEntering); /* + * windialogs.c + */ + +void +winDisplayExitDialog (winPrivScreenPtr pScreenPriv); + + +void +winDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv); + + +/* * winengine.c */ @@ -1377,6 +1428,33 @@ winSetShapePRootless (WindowPtr pWindow); /* + * winmultiwindowicons.c + */ + +HICON +winXIconToHICON (WindowPtr pWin); + +void +winUpdateIcon (Window id); + + +/* + * winmultiwindowshape.c + */ + +#ifdef SHAPE +void +winReshapeMultiWindow (WindowPtr pWin); + +void +winSetShapeMultiWindow (WindowPtr pWindow); + +void +winUpdateRgnMultiWindow (WindowPtr pWindow); +#endif + + +/* * winmultiwindowwindow.c */ @@ -1404,10 +1482,42 @@ winReparentWindowMultiWindow (WindowPtr pWin, WindowPtr pPriorParent); void winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib); -#ifdef SHAPE void -winSetShapeMultiWindow (WindowPtr pWindow); -#endif +winReorderWindowsMultiWindow (ScreenPtr pScreen); + +void +winMoveXWindow (WindowPtr pWin, int x, int y); + +void +winResizeXWindow (WindowPtr pWin, int w, int h); + +XID +winGetWindowID (WindowPtr pWin); + + +/* + * winmultiwindowwndproc.c + */ + +LRESULT CALLBACK +winTopLevelWindowProc (HWND hwnd, UINT message, + WPARAM wParam, LPARAM lParam); + + +/* + * wintrayicon.c + */ + +void +winInitNotifyIcon (winPrivScreenPtr pScreenPriv); + +void +winDeleteNotifyIcon (winPrivScreenPtr pScreenPriv); + +LRESULT +winHandleIconMessage (HWND hwnd, UINT message, + WPARAM wParam, LPARAM lParam, + winPrivScreenPtr pScreenPriv); /* diff --git a/hw/xwin/winblock.c b/hw/xwin/winblock.c index 45d509fea..cc057eed6 100644 --- a/hw/xwin/winblock.c +++ b/hw/xwin/winblock.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winblock.c,v 1.6 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winblock.c,v 1.7 2003/07/29 21:25:16 dawes Exp $ */ #include "win.h" @@ -68,9 +68,13 @@ winBlockHandler_ProcessMessages: /* Process all messages on our queue */ while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { - if (g_hDlgDepthChange == 0 || !IsDialogMessage (g_hDlgDepthChange, &msg)) + if ((g_hDlgDepthChange == 0 + || !IsDialogMessage (g_hDlgDepthChange, &msg)) + && (g_hDlgExit == 0 + || !IsDialogMessage (g_hDlgExit, &msg))) { DispatchMessage (&msg); } } + winReorderWindowsMultiWindow ((ScreenPtr)pBlockData); } diff --git a/hw/xwin/winclipboard.h b/hw/xwin/winclipboard.h index 6e6cf44a9..8f9bae789 100644 --- a/hw/xwin/winclipboard.h +++ b/hw/xwin/winclipboard.h @@ -27,7 +27,7 @@ * * Authors: Harold Hunt */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboard.h,v 1.1 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboard.h,v 1.3 2003/10/02 13:30:10 eich Exp $ */ #ifndef _WINCLIPBOARD_H_ @@ -119,6 +119,8 @@ winClipboardUNIXtoDOS (unsigned char **ppszData, int iLength); void * winClipboardProc (void *pArg); +void +winDeinitClipboard (); /* * winclipboardunicode.c diff --git a/hw/xwin/winclipboardinit.c b/hw/xwin/winclipboardinit.c index 22c068c48..a1f7b0b6d 100644 --- a/hw/xwin/winclipboardinit.c +++ b/hw/xwin/winclipboardinit.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardinit.c,v 1.1 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardinit.c,v 1.2 2003/07/29 21:25:16 dawes Exp $ */ #include "winclipboard.h" diff --git a/hw/xwin/winclipboardtextconv.c b/hw/xwin/winclipboardtextconv.c index f97681c5f..09ef40076 100644 --- a/hw/xwin/winclipboardtextconv.c +++ b/hw/xwin/winclipboardtextconv.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardtextconv.c,v 1.1 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardtextconv.c,v 1.2 2003/07/29 21:25:16 dawes Exp $ */ #include "win.h" #include <stdio.h> diff --git a/hw/xwin/winclipboardthread.c b/hw/xwin/winclipboardthread.c index ce4590b98..06a985533 100644 --- a/hw/xwin/winclipboardthread.c +++ b/hw/xwin/winclipboardthread.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardthread.c,v 1.1 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardthread.c,v 1.3 2003/10/02 13:30:10 eich Exp $ */ #include "winclipboard.h" @@ -43,6 +43,7 @@ extern Bool g_fCalledSetLocale; */ static jmp_buf g_jmpEntry; +static Bool g_shutdown = FALSE; /* @@ -79,7 +80,6 @@ winClipboardProc (void *pArg) int iRetries; Bool fUnicodeSupport; char szDisplay[512]; - int i; ClipboardProcArgPtr pProcArg = (ClipboardProcArgPtr) pArg; ErrorF ("winClipboardProc - Hello\n"); @@ -93,7 +93,7 @@ winClipboardProc (void *pArg) ErrorF ("winClipboardProc - Calling pthread_mutex_lock ()\n"); - /* Grab our garbage mutex to satisfy pthread_cond_wait */ + /* Grab the server started mutex - pause until we get it */ iReturn = pthread_mutex_lock (pProcArg->ppmServerStarted); if (iReturn != 0) { @@ -129,11 +129,6 @@ winClipboardProc (void *pArg) /* Flag that we have called setlocale */ g_fCalledSetLocale = TRUE; - /* Release the garbage mutex */ - pthread_mutex_unlock (pProcArg->ppmServerStarted); - - ErrorF ("winClipboardProc - pthread_mutex_unlock () returned.\n"); - /* Allow multiple threads to access Xlib */ if (XInitThreads () == 0) { @@ -143,6 +138,11 @@ winClipboardProc (void *pArg) ErrorF ("winClipboardProc - XInitThreads () returned.\n"); + /* Release the server started mutex */ + pthread_mutex_unlock (pProcArg->ppmServerStarted); + + ErrorF ("winClipboardProc - pthread_mutex_unlock () returned.\n"); + /* Set jump point for Error exits */ iReturn = setjmp (g_jmpEntry); @@ -155,6 +155,12 @@ 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); @@ -163,13 +169,12 @@ winClipboardProc (void *pArg) /* Initialize retry count */ iRetries = 0; -#if 0 - /* Setup the display connection string x */ - snprintf (szDisplay, 512, "127.0.0.1:%s.%d", display, pProcArg->dwScreen); -#else /* Setup the display connection string x */ - snprintf (szDisplay, 512, ":%s.%d", display, pProcArg->dwScreen); -#endif + snprintf (szDisplay, + 512, + "127.0.0.1:%s.%d", + display, + (int) pProcArg->dwScreen); /* Print the display connection string */ ErrorF ("winClipboardProc - DISPLAY=%s\n", szDisplay); @@ -434,14 +439,18 @@ 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 (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; } @@ -461,3 +470,15 @@ winClipboardIOErrorHandler (Display *pDisplay) 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 fdbcb8e69..9eb2b0d87 100644 --- a/hw/xwin/winclipboardunicode.c +++ b/hw/xwin/winclipboardunicode.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardunicode.c,v 1.1 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardunicode.c,v 1.2 2003/07/29 21:25:16 dawes Exp $ */ #include "win.h" diff --git a/hw/xwin/winclipboardwndproc.c b/hw/xwin/winclipboardwndproc.c index d27bb4861..c577d060e 100644 --- a/hw/xwin/winclipboardwndproc.c +++ b/hw/xwin/winclipboardwndproc.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardwndproc.c,v 1.1 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardwndproc.c,v 1.2 2003/07/29 21:25:16 dawes Exp $ */ #include "winclipboard.h" diff --git a/hw/xwin/winclipboardxevents.c b/hw/xwin/winclipboardxevents.c index a09c7c185..8b3a56489 100644 --- a/hw/xwin/winclipboardxevents.c +++ b/hw/xwin/winclipboardxevents.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardxevents.c,v 1.1 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winclipboardxevents.c,v 1.3 2003/10/02 13:30:10 eich Exp $ */ #include "winclipboard.h" @@ -81,11 +81,12 @@ winClipboardFlushXEvents (HWND hwnd, case ClientMessage: if (event.xclient.data.l[0] == atomDeleteWindow) { - ErrorF ("\nReceived WM_DELETE_WINDOW\n\n"); + ErrorF ("\nwinClipboardFlushXEvents - Received " + "WM_DELETE_WINDOW\n\n"); fReturn = FALSE; } else - ErrorF ("\nUnknown ClientMessage\n\n"); + ErrorF ("\nwinClipboardFlushXEvents - Unknown ClientMessage\n\n"); break; case SelectionClear: @@ -98,7 +99,8 @@ winClipboardFlushXEvents (HWND hwnd, CurrentTime); if (iReturn == BadAtom || iReturn == BadWindow) { - ErrorF ("SelectionClear - XConvertSelection () failed\n"); + ErrorF ("winClipboardFlushXEvents - SelectionClear - " + "XConvertSelection () failed\n"); pthread_exit (NULL); } break; @@ -146,7 +148,8 @@ winClipboardFlushXEvents (HWND hwnd, (XEvent *) &eventSelection); if (iReturn == BadValue || iReturn == BadWindow) { - ErrorF ("SelectionRequest - XSendEvent () failed\n"); + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + "XSendEvent () failed\n"); pthread_exit (NULL); } @@ -176,7 +179,8 @@ winClipboardFlushXEvents (HWND hwnd, || iReturn == BadValue || iReturn == BadWindow) { - ErrorF ("SelectionRequest - XChangeProperty failed: %d\n", + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + "XChangeProperty failed: %d\n", iReturn); } @@ -201,7 +205,8 @@ winClipboardFlushXEvents (HWND hwnd, (XEvent *) &eventSelection); if (iReturn == BadValue || iReturn == BadWindow) { - ErrorF ("SelectionRequest - XSendEvent () failed\n"); + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + "XSendEvent () failed\n"); } break; } @@ -209,7 +214,8 @@ winClipboardFlushXEvents (HWND hwnd, /* Access the clipboard */ if (!OpenClipboard (hwnd)) { - ErrorF ("SelectionRequest - OpenClipboard () failed: %08x\n", + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + "OpenClipboard () failed: %08x\n", GetLastError ()); pthread_exit (NULL); } @@ -235,7 +241,8 @@ winClipboardFlushXEvents (HWND hwnd, hGlobal = GetClipboardData (CF_TEXT); if (!hGlobal) { - ErrorF ("SelectionRequest - GetClipboardData () failed: %08x\n", + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + "GetClipboardData () failed: %08x\n", GetLastError ()); pthread_exit (NULL); } @@ -283,8 +290,8 @@ winClipboardFlushXEvents (HWND hwnd, &xtpText); if (iReturn == XNoMemory || iReturn == XLocaleNotSupported) { - ErrorF ("SelectionRequest - Xutf8TextListToTextProperty " - "failed: %d\n", + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + "Xutf8TextListToTextProperty failed: %d\n", iReturn); exit(1); } @@ -324,7 +331,8 @@ winClipboardFlushXEvents (HWND hwnd, || iReturn == BadMatch || iReturn == BadValue || iReturn == BadWindow) { - ErrorF ("SelectionRequest - XChangeProperty failed: %d\n", + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + "XChangeProperty failed: %d\n", iReturn); pthread_exit (NULL); } @@ -359,7 +367,8 @@ winClipboardFlushXEvents (HWND hwnd, (XEvent *) &eventSelection); if (iReturn == BadValue || iReturn == BadWindow) { - ErrorF ("SelectionRequest - XSendEvent () failed\n"); + ErrorF ("winClipboardFlushXEvents - SelectionRequest - " + "XSendEvent () failed\n"); pthread_exit (NULL); } break; @@ -379,7 +388,7 @@ winClipboardFlushXEvents (HWND hwnd, pszAtomName = XGetAtomName (pDisplay, event.xselection.selection); - ErrorF ("SelectionNotify - ATOM: %s\n", + ErrorF ("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n", pszAtomName); XFree (pszAtomName); @@ -406,13 +415,15 @@ winClipboardFlushXEvents (HWND hwnd, if(event.xselection.target == XA_STRING) { #if 0 - ErrorF ("SelectionNotify XA_STRING\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XA_STRING\n"); #endif return fReturn; } else if (event.xselection.target == atomUTF8String) { - ErrorF ("SelectionNotify UTF8\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify " + "UTF8\n"); iReturn = XConvertSelection (pDisplay, event.xselection.selection, XA_STRING, @@ -421,15 +432,16 @@ winClipboardFlushXEvents (HWND hwnd, CurrentTime); if (iReturn == BadAtom || iReturn == BadWindow) { - ErrorF ("SelectionNotify - XConvertSelection () " - "failed\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify " + "- XConvertSelection () failed\n"); pthread_exit (NULL); } return fReturn; } else if (event.xselection.target == atomCompoundText) { - ErrorF ("SelectionNotify CompoundText\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify " + "CompoundText\n"); iReturn = XConvertSelection (pDisplay, event.xselection.selection, atomUTF8String, @@ -438,15 +450,15 @@ winClipboardFlushXEvents (HWND hwnd, CurrentTime); if (iReturn == BadAtom || iReturn == BadWindow) { - ErrorF ("SelectionNotify - XConvertSelection () " - "failed\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify " + "- XConvertSelection () failed\n"); pthread_exit (NULL); } return fReturn; } else { - ErrorF("Unknown format\n"); + ErrorF ("winClipboardFlushXEvents - Unknown format\n"); return fReturn; } } @@ -481,7 +493,8 @@ winClipboardFlushXEvents (HWND hwnd, &pszReturnData); if (iReturn != Success) { - ErrorF ("SelectionNotify - XGetWindowProperty () failed\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XGetWindowProperty () failed\n"); pthread_exit (NULL); } @@ -523,7 +536,8 @@ winClipboardFlushXEvents (HWND hwnd, &pszReturnData); if (iReturn != Success) { - ErrorF ("SelectionNotify - XGetWindowProperty () failed\n"); + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "XGetWindowProperty () failed\n"); pthread_exit (NULL); } @@ -591,14 +605,16 @@ winClipboardFlushXEvents (HWND hwnd, /* Access the Windows clipboard */ if (!OpenClipboard (hwnd)) { - ErrorF ("OpenClipboard () failed: %08x\n", GetLastError ()); + ErrorF ("winClipboardFlushXEvents - OpenClipboard () failed: " + "%08x\n", GetLastError ()); pthread_exit (NULL); } /* Take ownership of the Window clipboard */ if (!EmptyClipboard ()) { - ErrorF ("EmptyClipboard () failed: %08x\n", GetLastError ()); + ErrorF ("winClipboardFlushXEvents - EmptyClipboard () failed: " + "%08x\n", GetLastError ()); pthread_exit (NULL); } @@ -613,7 +629,8 @@ winClipboardFlushXEvents (HWND hwnd, pszGlobalData = GlobalLock (hGlobal); if (pszGlobalData == NULL) { - ErrorF ("Could not lock global memory for clipboard transfer\n"); + ErrorF ("winClipboardFlushXEvents - Could not lock global " + "memory for clipboard transfer\n"); pthread_exit (NULL); } @@ -655,7 +672,9 @@ winClipboardFlushXEvents (HWND hwnd, /* Release the clipboard */ if (!CloseClipboard ()) { - ErrorF ("CloseClipboard () failed: %08x\n", GetLastError ()); + ErrorF ("winClipboardFlushXEvents - CloseClipboard () failed: " + "%08x\n", + GetLastError ()); pthread_exit (NULL); } @@ -669,8 +688,9 @@ winClipboardFlushXEvents (HWND hwnd, pszAtomName = XGetAtomName (pDisplay, event.xselection.selection); - ErrorF ("SelectionNotify - Could not reassert ownership " - "of selection ATOM: %s\n", pszAtomName); + ErrorF ("winClipboardFlushXEvents - SelectionNotify - " + "Could not reassert ownership of selection ATOM: %s\n", + pszAtomName); XFree (pszAtomName); pszAtomName = NULL; pthread_exit (NULL); @@ -695,7 +715,8 @@ winClipboardFlushXEvents (HWND hwnd, iWindow, CurrentTime); if (iReturn == BadAtom || iReturn == BadWindow) { - ErrorF ("Could not reassert ownership of selection\n"); + ErrorF ("winClipboardFlushXEvents - Could not reassert " + "ownership of selection\n"); pthread_exit (NULL); } #endif diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c index bc336527c..b42b1d6bf 100644 --- a/hw/xwin/winconfig.c +++ b/hw/xwin/winconfig.c @@ -27,7 +27,7 @@ * * Authors: Alexander Gottwald */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winconfig.c,v 1.1 2002/10/17 08:18:22 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winconfig.c,v 1.4 2003/10/08 11:13:02 eich Exp $ */ #include "win.h" #include "winconfig.h" @@ -112,11 +112,10 @@ static Bool GetBoolValue (OptionInfoPtr p, const char *s); Bool winReadConfigfile () { - Bool retval = TRUE; - const char *filename; - - MessageType from = X_DEFAULT; - char *xf86ConfigFile = NULL; + Bool retval = TRUE; + const char *filename; + MessageType from = X_DEFAULT; + char *xf86ConfigFile = NULL; if (g_cmdline.configFile) { @@ -146,16 +145,7 @@ winReadConfigfile () } xf86closeConfigFile (); - winMsg (X_NONE, "Markers: "); - winMsg (X_PROBED, "probed, "); - winMsg (X_CONFIG, "from config file, "); - winMsg (X_DEFAULT, "default setting,\n "); - winMsg (X_CMDLINE, "from command line, "); - winMsg (X_NOTICE, "notice, "); - winMsg (X_INFO, "informational,\n "); - winMsg (X_WARNING, "warning, "); - winMsg (X_ERROR, "error, "); - winMsg (X_UNKNOWN, "unknown.\n"); + LogPrintMarkers(); /* set options from data structure */ @@ -213,9 +203,46 @@ winReadConfigfile () /* Set the keyboard configuration */ +typedef struct { + unsigned int winlayout; + int winkbtype; + char *xkbmodel; + char *xkblayout; + char *xkbvariant; + char *xkboptions; + char *layoutname; +} WinKBLayoutRec, *WinKBLayoutPtr; + +WinKBLayoutRec winKBLayouts[] = { + { 0x405, -1, "pc105", "cz", NULL, NULL, "Czech"}, + { 0x406, -1, "pc105", "dk", NULL, NULL, "Danish"}, + { 0x407, -1, "pc105", "de", NULL, NULL, "German (Germany)"}, + {0x10407, -1, "pc105", "de", NULL, NULL, "German (Germany, IBM)"}, + { 0x807, -1, "pc105", "de_CH", NULL, NULL, "German (Switzerland)"}, + {0x10409, -1, "pc105", "dvorak", NULL, NULL, "English (USA, Dvorak)"}, + {0x20409, -1, "pc105", "us_intl", NULL, NULL, "English (USA, International)"}, + { 0x809, -1, "pc105", "gb", NULL, NULL, "English (United Kingdom)"}, + { 0x40a, -1, "pc105", "es", NULL, NULL, "Spanish (Spain, Traditional Sort)"}, + { 0x40b, -1, "pc105", "fi", NULL, NULL, "Finnish"}, + { 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"}, + { 0x414, -1, "pc105", "no", NULL, NULL, "Norwegian"}, + { 0x416, -1, "pc105", "pt", 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)"}, + { -1, -1, NULL, NULL, NULL, NULL, NULL} +}; + + Bool winConfigKeyboard (DeviceIntPtr pDevice) { + char layoutName[KL_NAMELENGTH]; + unsigned int layoutNum; + int keyboardType; XF86ConfInputPtr kbd = NULL; XF86ConfInputPtr input_list = NULL; MessageType from = X_DEFAULT; @@ -237,6 +264,44 @@ winConfigKeyboard (DeviceIntPtr pDevice) g_winInfo.xkb.variant = NULL; g_winInfo.xkb.options = NULL; # endif /* PC98 */ + + + + keyboardType = GetKeyboardType (0); + if (keyboardType > 0 && GetKeyboardLayoutName (layoutName)) + { + WinKBLayoutPtr pLayout; + + 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 */ + layoutNum = (layoutNum & 0xffff); + } + winMsg (X_DEFAULT, "winConfigKeyboard - Layout: \"%s\" (%08x) \n", + layoutName, layoutNum); + + for (pLayout = winKBLayouts; pLayout->winlayout != -1; pLayout++) + { + if (pLayout->winlayout != layoutNum) + continue; + if (pLayout->winkbtype > 0 && pLayout->winkbtype != keyboardType) + continue; + + winMsg (X_DEFAULT, + "Using preset keyboard for \"%s\" (%s), type \"%d\"\n", + pLayout->layoutname, layoutName, keyboardType); + + g_winInfo.xkb.model = pLayout->xkbmodel; + g_winInfo.xkb.layout = pLayout->xkblayout; + g_winInfo.xkb.variant = pLayout->xkbvariant; + g_winInfo.xkb.options = pLayout->xkboptions; + break; + } + } + g_winInfo.xkb.initialMap = NULL; g_winInfo.xkb.keymap = NULL; g_winInfo.xkb.types = NULL; @@ -265,7 +330,7 @@ winConfigKeyboard (DeviceIntPtr pDevice) { /* Check if device name matches requested name */ if (g_cmdline.keyboard && winNameCompare (input_list->inp_identifier, - g_cmdline.keyboard)) + g_cmdline.keyboard)) continue; kbd = input_list; } @@ -416,7 +481,7 @@ winConfigMouse (DeviceIntPtr pDevice) { /* Check if device name matches requested name */ if (g_cmdline.mouse && winNameCompare (input_list->inp_identifier, - g_cmdline.mouse)) + g_cmdline.mouse)) continue; mouse = input_list; } diff --git a/hw/xwin/wincreatewnd.c b/hw/xwin/wincreatewnd.c index 3c725f248..336131c8a 100644 --- a/hw/xwin/wincreatewnd.c +++ b/hw/xwin/wincreatewnd.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/wincreatewnd.c,v 1.5 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/wincreatewnd.c,v 1.7 2003/10/08 11:13:03 eich Exp $ */ #include "win.h" #include "shellapi.h" @@ -57,6 +57,7 @@ winCreateBoundingWindowFullScreen (ScreenPtr pScreen) int iHeight = pScreenInfo->dwHeight; HWND *phwnd = &pScreenPriv->hwndScreen; WNDCLASS wc; + char szTitle[256]; #if CYGDEBUG ErrorF ("winCreateBoundingWindowFullScreen\n"); @@ -75,10 +76,23 @@ winCreateBoundingWindowFullScreen (ScreenPtr pScreen) wc.lpszClassName = WINDOW_CLASS; RegisterClass (&wc); + /* Set display and screen-specific tooltip text */ + if (g_pszQueryHost != NULL) + snprintf (szTitle, + sizeof (szTitle), + WINDOW_TITLE_XDMCP, + g_pszQueryHost); + else + snprintf (szTitle, + sizeof (szTitle), + WINDOW_TITLE, + display, + (int) pScreenInfo->dwScreen); + /* Create the window */ *phwnd = CreateWindowExA (WS_EX_TOPMOST, /* Extended styles */ WINDOW_CLASS, /* Class name */ - WINDOW_TITLE, /* Window name */ + szTitle, /* Window name */ WS_POPUP, 0, /* Horizontal position */ 0, /* Vertical position */ @@ -102,7 +116,7 @@ winCreateBoundingWindowFullScreen (ScreenPtr pScreen) ShowWindow (*phwnd, SW_SHOWNORMAL); break; } - + /* Send first paint message */ UpdateWindow (*phwnd); @@ -128,6 +142,7 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) WNDCLASS wc; RECT rcClient, rcWorkArea; DWORD dwWindowStyle; + char szTitle[256]; ErrorF ("winCreateBoundingWindowWindowed - User w: %d h: %d\n", pScreenInfo->dwUserWidth, pScreenInfo->dwUserHeight); @@ -267,10 +282,23 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) iWidth, iHeight); #endif + /* Set display and screen-specific tooltip text */ + if (g_pszQueryHost != NULL) + snprintf (szTitle, + sizeof (szTitle), + WINDOW_TITLE_XDMCP, + g_pszQueryHost); + else + snprintf (szTitle, + sizeof (szTitle), + WINDOW_TITLE, + display, + (int) pScreenInfo->dwScreen); + /* Create the window */ *phwnd = CreateWindowExA (0, /* Extended styles */ WINDOW_CLASS, /* Class name */ - WINDOW_TITLE, /* Window name */ + szTitle, /* Window name */ dwWindowStyle, rcWorkArea.left, /* Horizontal position */ rcWorkArea.top, /* Vertical position */ @@ -369,7 +397,10 @@ winCreateBoundingWindowWindowed (ScreenPtr pScreen) /* Show the window */ if (pScreenInfo->fMultiWindow) - ShowWindow (*phwnd, SW_SHOWMINNOACTIVE); + { + pScreenPriv->fRootWindowShown = FALSE; + ShowWindow (*phwnd, SW_HIDE); + } else ShowWindow (*phwnd, SW_SHOWNORMAL); if (!UpdateWindow (*phwnd)) diff --git a/hw/xwin/wincursor.c b/hw/xwin/wincursor.c index cd12bb632..e7c3ba7e7 100644 --- a/hw/xwin/wincursor.c +++ b/hw/xwin/wincursor.c @@ -30,7 +30,7 @@ * Peter Busch * Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/wincursor.c,v 1.5 2002/07/05 09:19:26 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/wincursor.c,v 1.6 2003/07/29 21:25:17 dawes Exp $ */ #include "win.h" @@ -47,6 +47,21 @@ winPointerWarpCursor (ScreenPtr pScreen, int x, int y) { winScreenPriv(pScreen); RECT rcClient; + static Bool s_fInitialWarp = TRUE; + + /* Discard first warp call */ + if (s_fInitialWarp) + { + /* First warp moves mouse to center of window, just ignore it */ + + /* Don't ignore subsequent warps */ + s_fInitialWarp = FALSE; + + ErrorF ("winPointerWarpCursor - Discarding first warp: %d %d\n", + x, y); + + return; + } /* Only update the Windows cursor position if we are active */ if (pScreenPriv->hwndScreen == GetForegroundWindow ()) diff --git a/hw/xwin/winengine.c b/hw/xwin/winengine.c index aff90bdaf..d76e58628 100644 --- a/hw/xwin/winengine.c +++ b/hw/xwin/winengine.c @@ -27,12 +27,19 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winengine.c,v 1.4 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winengine.c,v 1.5 2003/07/29 21:25:17 dawes Exp $ */ #include "win.h" /* + * External global variables + */ + +extern const GUID _IID_IDirectDraw4; + + +/* * Detect engines supported by current Windows version * DirectDraw version and hardware */ diff --git a/hw/xwin/winerror.c b/hw/xwin/winerror.c index c18f10dde..8a1e0df85 100644 --- a/hw/xwin/winerror.c +++ b/hw/xwin/winerror.c @@ -27,29 +27,21 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winerror.c,v 1.4 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winerror.c,v 1.6 2003/10/02 13:30:10 eich Exp $ */ #include "win.h" -extern FILE *g_pfLog; - #ifdef DDXOSVERRORF void OsVendorVErrorF (const char *pszFormat, va_list va_args) { static pthread_mutex_t s_pmPrinting = PTHREAD_MUTEX_INITIALIZER; - /* Check we opened the log file first */ - if (g_pfLog == NULL) return; - /* Lock the printing mutex */ pthread_mutex_lock (&s_pmPrinting); /* Print the error message to a log file, could be stderr */ - vfprintf (g_pfLog, pszFormat, va_args); - - /* Flush after every write, to make updates show up quickly */ - fflush (g_pfLog); + LogVWrite(0, pszFormat, va_args); /* Unlock the printing mutex */ pthread_mutex_unlock (&s_pmPrinting); diff --git a/hw/xwin/winfillsp.c b/hw/xwin/winfillsp.c index faf9c67fc..9ac536274 100644 --- a/hw/xwin/winfillsp.c +++ b/hw/xwin/winfillsp.c @@ -26,11 +26,27 @@ *from the XFree86 Project. * * Authors: Harold L Hunt II + * Alan Hourihane <alanh@fairlite.demon.co.uk> */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winfillsp.c,v 1.9 2001/11/01 12:19:40 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winfillsp.c,v 1.10 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" +extern void ROP16(HDC hdc, int rop); + +#define TRANSLATE_COLOR(color) \ +{ \ + if (pDrawable->depth == 15) \ + color = ((color & 0x1F) << 19) | ((color & 0x03E0) << 6) | \ + ((color & 0xF800) >> 8); \ + else if (pDrawable->depth == 16) \ + color = ((color & 0x1F) << 19) | ((color & 0x07E0) << 5) | \ + ((color & 0xF800) >> 8); \ + else if (pDrawable->depth == 24 || pDrawable->depth == 32) \ + color = ((color & 0xFF) << 16) | (color & 0xFF00) | \ + ((color & 0xFF0000) >> 16); \ +} + /* See Porting Layer Definition - p. 54 */ void winFillSpansNativeGDI (DrawablePtr pDrawable, @@ -41,87 +57,57 @@ winFillSpansNativeGDI (DrawablePtr pDrawable, int fSorted) { winGCPriv(pGC); - int iSpan; - DDXPointPtr pPoint = NULL; - int *piWidth = 0; HBITMAP hbmpOrig = NULL, hbmpOrigStipple = NULL; + HBITMAP hPenOrig = NULL; + HBITMAP hBitmap = NULL; PixmapPtr pPixmap = NULL; winPrivPixmapPtr pPixmapPriv = NULL; - HBITMAP hbmpFilledStipple = NULL, hbmpMaskedForeground = NULL; PixmapPtr pStipple = NULL; winPrivPixmapPtr pStipplePriv = NULL; PixmapPtr pTile = NULL; winPrivPixmapPtr pTilePriv = NULL; - HBRUSH hbrushStipple = NULL; - HDC hdcStipple = NULL; - BYTE *pbbitsFilledStipple = NULL; + HDC hdcStipple = NULL, hdcTile = NULL; + HPEN hPen = NULL; int iX; - DEBUG_FN_NAME("winFillSpans"); - DEBUGVARS; - DEBUGPROC_MSG; + int fg, bg; + RegionPtr pClip = pGC->pCompositeClip; + BoxPtr pextent, pbox; + int nbox; + int extentX1, extentX2, extentY1, extentY2; + int fullX1, fullX2, fullY1; + HRGN hrgn = NULL, combined = NULL; + + nbox = REGION_NUM_RECTS (pClip); + pbox = REGION_RECTS (pClip); + + if (!nbox) return; + + combined = CreateRectRgn (pbox->x1, pbox->y1, pbox->x2, pbox->y2); + nbox--; pbox++; + + while (nbox--) + { + hrgn = CreateRectRgn (pbox->x1, pbox->y1, pbox->x2, pbox->y2); + CombineRgn (combined, combined, hrgn, RGN_OR); + DeleteObject (hrgn); + hrgn = NULL; + pbox++; + } + + pextent = REGION_EXTENTS (pGC->pScreen, pClip); + extentX1 = pextent->x1; + extentY1 = pextent->y1; + extentX2 = pextent->x2; + extentY2 = pextent->y2; /* Branch on the type of drawable we have */ switch (pDrawable->type) { case DRAWABLE_PIXMAP: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP\n"); -#if 0 - /* Branch on the raster operation type */ - switch (pGC->alu) - { - case GXclear: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXclear\n"); - break; - case GXand: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXand\n"); - break; - case GXandReverse: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXandReverse\n"); - break; - case GXcopy: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXcopy\n"); - break; - case GXandInverted: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXandInverted\n"); - break; - case GXnoop: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXnoop\n"); - break; - case GXxor: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXxor\n"); - break; - case GXor: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXor\n"); - break; - case GXnor: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXnor\n"); - break; - case GXequiv: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXequiv\n"); - break; - case GXinvert: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXinvert\n"); - break; - case GXorReverse: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXorReverse\n"); - break; - case GXcopyInverted: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXcopyInverted\n"); - break; - case GXorInverted: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXorInverted\n"); - break; - case GXnand: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXnand\n"); - break; - case GXset: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - GXset\n"); - break; - default: - FatalError ("winFillSpans - DRAWABLE_PIXMAP - Unknown ROP\n"); - break; - } -#endif + + SelectClipRgn (pGCPriv->hdcMem, combined); + DeleteObject (combined); + combined = NULL; /* Get a pixmap pointer from the drawable pointer, and fetch privates */ pPixmap = (PixmapPtr) pDrawable; @@ -131,268 +117,639 @@ winFillSpansNativeGDI (DrawablePtr pDrawable, hbmpOrig = SelectObject (pGCPriv->hdcMem, pPixmapPriv->hBitmap); if (hbmpOrig == NULL) FatalError ("winFillSpans - DRAWABLE_PIXMAP - " - "SelectObject () failed on pPixmapPriv->hBitmap\n"); + "SelectObject () failed on\n\tpPixmapPriv->hBitmap: " + "%08x\n", pPixmapPriv->hBitmap); /* Branch on the fill type */ switch (pGC->fillStyle) { case FillSolid: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - FillSolid %08x\n", - pDrawable); - - /* - * REMOVE - Visual verification only. - */ - BitBlt (pGCPriv->hdc, - pDrawable->width, pDrawable->height, - pDrawable->width, pDrawable->height, - pGCPriv->hdcMem, - 0, 0, - SRCCOPY); - DEBUG_MSG ("FillSolid - Original bitmap"); - - /* Enumerate spans */ - for (iSpan = 0; iSpan < iSpans; ++iSpan) + + ROP16 (pGCPriv->hdcMem, pGC->alu); + + if (pDrawable->depth == 1) { - /* Get pointers to the current span location and width */ - pPoint = pPoints + iSpan; - piWidth = piWidths + iSpan; - - /* Display some useful information */ - ErrorF ("(%dx%dx%d) (%d,%d) fg: %d bg: %d w: %d\n", - pDrawable->width, pDrawable->height, pDrawable->depth, - pPoint->x, pPoint->y, - pGC->fgPixel, pGC->bgPixel, - *piWidth); - - /* Draw the requested line */ - MoveToEx (pGCPriv->hdcMem, pPoint->x, pPoint->y, NULL); - LineTo (pGCPriv->hdcMem, pPoint->x + *piWidth, pPoint->y); + if (pGC->fgPixel == 0) + hPenOrig = SelectObject (pGCPriv->hdcMem, + GetStockObject (BLACK_PEN)); + else + hPenOrig = SelectObject (pGCPriv->hdcMem, + GetStockObject (WHITE_PEN)); + } + else + { + fg = pGC->fgPixel; + TRANSLATE_COLOR (fg); + hPen = CreatePen (PS_SOLID, 0, fg); + hPenOrig = SelectObject (pGCPriv->hdcMem, hPen); + } + + while (iSpans--) + { + fullX1 = pPoints->x; + fullY1 = pPoints->y; + fullX2 = fullX1 + (int) *piWidths; + pPoints++; + piWidths++; + + if (fullY1 < extentY1 || extentY2 <= fullY1) + continue; + + if (fullX1 < extentX1) + fullX1 = extentX1; + if (fullX2 > extentX2) + fullX2 = extentX2; + + if (fullX1 >= fullX2) + continue; + + MoveToEx (pGCPriv->hdcMem, fullX1, fullY1, NULL); + LineTo (pGCPriv->hdcMem, fullX2, fullY1); } - /* - * REMOVE - Visual verification only. - */ - BitBlt (pGCPriv->hdc, - pDrawable->width * 2, pDrawable->height, - pDrawable->width, pDrawable->height, - pGCPriv->hdcMem, - 0, 0, - SRCCOPY); - DEBUG_MSG ("FillSolid - Filled bitmap"); - - - /* Push the drawable pixmap out of the GC HDC */ - SelectObject (pGCPriv->hdcMem, hbmpOrig); - break; + SetROP2 (pGCPriv->hdcMem, R2_COPYPEN); - case FillStippled: - ErrorF ("winFillSpans - DRAWABLE_PIXMAP - FillStippled %08x\n", - pDrawable); + /* Give back the Pen */ + SelectObject (pGCPriv->hdcMem, hPenOrig); - /* - * FIXME: Assuming that pGC->patOrg.x = pGC->patOrg.y = 0 - */ + if (pDrawable->depth != 1) + DeleteObject (hPen); + break; + + case FillOpaqueStippled: pStipple = pGC->stipple; pStipplePriv = winGetPixmapPriv (pStipple); - /* Create a memory DC to hold the stipple */ - hdcStipple = CreateCompatibleDC (pGCPriv->hdc); + /* Create a device-dependent bitmap for the stipple */ + hBitmap = CreateDIBitmap (pGCPriv->hdcMem, + (BITMAPINFOHEADER *)pStipplePriv->pbmih, + CBM_INIT, + pStipplePriv->pbBits, + (BITMAPINFO *)pStipplePriv->pbmih, + DIB_RGB_COLORS); - /* Create a destination sized compatible bitmap */ - hbmpFilledStipple = winCreateDIBNativeGDI (pDrawable->width, - pDrawable->height, - pDrawable->depth, - &pbbitsFilledStipple, - NULL); + /* Create a memory DC to hold the stipple */ + hdcStipple = CreateCompatibleDC (pGCPriv->hdcMem); /* Select the stipple bitmap into the stipple DC */ - hbmpOrigStipple = SelectObject (hdcStipple, hbmpFilledStipple); + hbmpOrigStipple = SelectObject (hdcStipple, hBitmap); if (hbmpOrigStipple == NULL) FatalError ("winFillSpans () - DRAWABLE_PIXMAP - FillStippled - " - "SelectObject () failed on hbmpFilledStipple\n"); + "SelectObject () failed on hbmpOrigStipple\n"); - /* Create a pattern brush from the original stipple */ - hbrushStipple = CreatePatternBrush (pStipplePriv->hBitmap); + /* Make a temporary copy of the foreground and background colors */ + bg = pGC->bgPixel; + fg = pGC->fgPixel; - /* Select the original stipple brush into the stipple DC */ - SelectObject (hdcStipple, hbrushStipple); + /* Translate the depth-dependent colors to Win32 COLORREFs */ + TRANSLATE_COLOR (fg); + TRANSLATE_COLOR (bg); + SetTextColor (pGCPriv->hdcMem, fg); + SetBkColor (pGCPriv->hdcMem, bg); - /* PatBlt the original stipple to the filled stipple */ - PatBlt (hdcStipple, - 0, 0, - pDrawable->width, pDrawable->height, - PATCOPY); + while (iSpans--) + { + int width = pStipple->drawable.width; + fullX1 = pPoints->x; + fullY1 = pPoints->y; + fullX2 = fullX1 + (int) *piWidths; + pPoints++; + piWidths++; + + if (fullY1 < extentY1 || extentY2 <= fullY1) + continue; + + if (fullX1 < extentX1) + fullX1 = extentX1; + if (fullX2 > extentX2) + fullX2 = extentX2; + + if (fullX1 >= fullX2) + continue; + + for (iX = fullX1; iX < fullX2; iX += width) + { + int xoffset; + + if ((iX + pStipple->drawable.width) > fullX2) + width = fullX2 - iX; + else + width = pStipple->drawable.width; + + if (iX == fullX1) + xoffset = (fullX1 - (pDrawable->x + (pGC->patOrg.x % pStipple->drawable.width) - pStipple->drawable.width)) % pStipple->drawable.width; + else + xoffset = 0; + + if (xoffset + width > pStipple->drawable.width) + width = pStipple->drawable.width - xoffset; + + BitBlt (pGCPriv->hdcMem, + iX, fullY1, + width, 1, + hdcStipple, + xoffset, + (fullY1 - (pDrawable->y + (pGC->patOrg.y % pStipple->drawable.height) - pStipple->drawable.height)) % pStipple->drawable.height, + g_copyROP[pGC->alu]); + } + } - /* - * REMOVE - Visual verification only. - */ - BitBlt (pGCPriv->hdc, - pDrawable->width, 0, - pDrawable->width, pDrawable->height, - hdcStipple, - 0, 0, - SRCCOPY); - DEBUG_MSG("Filled a drawable-sized stipple"); - - /* - * Mask out the bits from the drawable that are being preserved; - * hbmpFilledStipple now contains the preserved original bits. - */ - BitBlt (hdcStipple, - 0, 0, - pDrawable->width, pDrawable->height, - pGCPriv->hdcMem, - 0, 0, - SRCERASE); - - /* - * REMOVE - Visual verification only. - */ - BitBlt (pGCPriv->hdc, - pDrawable->width * 2, 0, - pDrawable->width, pDrawable->height, - hdcStipple, - 0, 0, - SRCCOPY); - DEBUG_MSG("Preserved original bits"); - - /* - * Create a destination sized compatible bitmap to hold - * the masked foreground color. - */ - hbmpMaskedForeground = winCreateDIBNativeGDI (pDrawable->width, - pDrawable->height, - pDrawable->depth, - NULL, - NULL); - - /* - * Select the masked foreground bitmap into the default memory DC; - * this should pop the drawable bitmap out of the default DC. - */ - if (SelectObject (pGCPriv->hdcMem, hbmpMaskedForeground) == NULL) + /* Clear the stipple HDC */ + SelectObject (hdcStipple, hbmpOrigStipple); + DeleteDC (hdcStipple); + + /* Delete the device dependent stipple bitmap */ + DeleteObject (hBitmap); + + break; + case FillStippled: + + pStipple = pGC->stipple; + pStipplePriv = winGetPixmapPriv (pStipple); + + /* Create a device-dependent bitmap for the stipple */ + hBitmap = CreateDIBitmap (pGCPriv->hdcMem, + (BITMAPINFOHEADER *)pStipplePriv->pbmih, + CBM_INIT, + pStipplePriv->pbBits, + (BITMAPINFO *)pStipplePriv->pbmih, + DIB_RGB_COLORS); + + /* Create a memory DC to hold the stipple */ + hdcStipple = CreateCompatibleDC (pGCPriv->hdcMem); + + /* Select the stipple bitmap into the stipple DC */ + hbmpOrigStipple = SelectObject (hdcStipple, hBitmap); + if (hbmpOrigStipple == NULL) FatalError ("winFillSpans () - DRAWABLE_PIXMAP - FillStippled - " - "SelectObject () failed on hbmpMaskedForeground\n"); - - /* Free the original drawable */ - DeleteObject (pPixmapPriv->hBitmap); - pPixmapPriv->hBitmap = NULL; - pPixmapPriv->pbBits = NULL; - - /* Select the stipple brush into the default memory DC */ - SelectObject (pGCPriv->hdcMem, hbrushStipple); - - /* Create the masked foreground bitmap using the original stipple */ - PatBlt (pGCPriv->hdcMem, - 0, 0, - pDrawable->width, pDrawable->height, - PATCOPY); - - /* - * REMOVE - Visual verification only. - */ - BitBlt (pGCPriv->hdc, - pDrawable->width * 3, 0, - pDrawable->width, pDrawable->height, - pGCPriv->hdcMem, - 0, 0, - SRCCOPY); - DEBUG_MSG("Masked foreground bitmap"); - - /* - * Combine the masked foreground with the masked drawable; - * hbmpFilledStipple will contain the drawable stipple filled - * with the current foreground color - */ - BitBlt (hdcStipple, - 0, 0, - pDrawable->width, pDrawable->height, - pGCPriv->hdcMem, - 0, 0, - SRCPAINT); - - /* - * REMOVE - Visual verification only. + "SelectObject () failed on hbmpOrigStipple\n"); + + /* Make a temporary copy of the foreground and background colors */ + bg = pGC->bgPixel; + fg = pGC->fgPixel; + + /* Translate the depth-dependent colors to Win32 COLORREFs */ + TRANSLATE_COLOR (fg); + TRANSLATE_COLOR (bg); + + /* this is fudgy, we should only invert on the last one + * We need to get the black/white pixels right in the + * colormap. But yeah ! it's working.. */ - BitBlt (pGCPriv->hdc, - pDrawable->width * 4, 0, - pDrawable->width, pDrawable->height, - hdcStipple, - 0, 0, - SRCCOPY); - DEBUG_MSG("Completed stipple"); - - /* Release the stipple DC */ - SelectObject (hdcStipple, hbmpOrig); - DeleteDC (hdcStipple); - - /* Pop the stipple pattern brush out of the default mem DC */ - SelectObject (pGCPriv->hdcMem, GetStockObject (WHITE_BRUSH)); + if (pGC->bgPixel != -1 && pGC->fgPixel != -1) + { + SetTextColor (pGCPriv->hdcMem, fg); + SetBkColor (pGCPriv->hdcMem, bg); + BitBlt (hdcStipple, + 0, 0, + pStipple->drawable.width, pStipple->drawable.height, + hdcStipple, + 0, 0, + 0x330008); + } + else if (pGC->bgPixel == -1) + { + SetTextColor (pGCPriv->hdcMem, fg); + SetBkMode (pGCPriv->hdcMem, TRANSPARENT); + BitBlt (hdcStipple, + 0, 0, + pStipple->drawable.width, pStipple->drawable.height, + hdcStipple, + 0, 0, + 0x330008); + } + else if (pGC->fgPixel == -1) + { + SetTextColor (pGCPriv->hdcMem, bg); + SetBkMode (pGCPriv->hdcMem, TRANSPARENT); +#if 0 + BitBlt (hdcStipple, + 0, 0, + pStipple->drawable.width, pStipple->drawable.height, + hdcStipple, + 0, 0, + 0x330008); +#endif + } - /* Destroy the original stipple pattern brush */ - DeleteObject (hbrushStipple); + while (iSpans--) + { + int width = pStipple->drawable.width; + fullX1 = pPoints->x; + fullY1 = pPoints->y; + fullX2 = fullX1 + (int) *piWidths; + pPoints++; + piWidths++; + + if (fullY1 < extentY1 || extentY2 <= fullY1) + continue; + + if (fullX1 < extentX1) + fullX1 = extentX1; + if (fullX2 > extentX2) + fullX2 = extentX2; + + if (fullX1 >= fullX2) + continue; + + for (iX = fullX1; iX < fullX2; iX += width) + { + int xoffset; + + if ((iX + pStipple->drawable.width) > fullX2) + width = fullX2 - iX; + else + width = pStipple->drawable.width; + + if (iX == fullX1) + xoffset = (fullX1 - (pDrawable->x + (pGC->patOrg.x % pStipple->drawable.width) - pStipple->drawable.width)) % pStipple->drawable.width; + else + xoffset = 0; + + if (xoffset + width > pStipple->drawable.width) + width = pStipple->drawable.width - xoffset; + + BitBlt (pGCPriv->hdcMem, + iX, fullY1, + width, 1, + hdcStipple, + xoffset, + (fullY1 - (pDrawable->y + (pGC->patOrg.y % pStipple->drawable.height) - pStipple->drawable.height)) % pStipple->drawable.height, + g_copyROP[pGC->alu]); + } + } - /* Clear the memory DC */ - SelectObject (pGCPriv->hdcMem, hbmpOrig); + /* Clear the stipple HDC */ + SelectObject (hdcStipple, hbmpOrigStipple); + DeleteDC (hdcStipple); - /* Free the masked foreground bitmap */ - DeleteObject (hbmpMaskedForeground); + /* Delete the device dependent stipple bitmap */ + DeleteObject (hBitmap); - /* Point the drawable to the new bitmap */ - pPixmapPriv->hBitmap = hbmpFilledStipple; - pPixmapPriv->pbBits = pbbitsFilledStipple; + /* Restore the background mode */ + SetBkMode (pGCPriv->hdcMem, OPAQUE); break; case FillTiled: - FatalError ("\nwinFillSpans - DRAWABLE_PIXMAP - FillTiled\n\n"); - break; - case FillOpaqueStippled: - FatalError ("winFillSpans - DRAWABLE_PIXMAP - OpaqueStippled\n"); + /* Get a pixmap pointer from the tile pointer, and fetch privates */ + pTile = (PixmapPtr) pGC->tile.pixmap; + pTilePriv = winGetPixmapPriv (pTile); + + /* Create a memory DC to hold the tile */ + hdcTile = CreateCompatibleDC (pGCPriv->hdcMem); + + /* Select the tile into a DC */ + hbmpOrig = SelectObject (hdcTile, pTilePriv->hBitmap); + if (hbmpOrig == NULL) + FatalError ("winFillSpans - DRAWABLE_PIXMAP - FillTiled - " + "SelectObject () failed on pTilePriv->hBitmap\n"); + + while (iSpans--) + { + int width = pTile->drawable.width; + fullX1 = pPoints->x; + fullY1 = pPoints->y; + fullX2 = fullX1 + (int) *piWidths; + pPoints++; + piWidths++; + + if (fullY1 < extentY1 || extentY2 <= fullY1) + continue; + + if (fullX1 < extentX1) + fullX1 = extentX1; + if (fullX2 > extentX2) + fullX2 = extentX2; + + if (fullX1 >= fullX2) + continue; + + for (iX = fullX1; iX < fullX2; iX += width) + { + int xoffset; + + if ((iX + pTile->drawable.width) > fullX2) + width = fullX2 - iX; + else + width = pTile->drawable.width; + + if (iX == fullX1) + xoffset = (fullX1 - (pDrawable->x + (pGC->patOrg.x % pTile->drawable.width) - pTile->drawable.width)) % pTile->drawable.width; + else + xoffset = 0; + + if (xoffset + width > pTile->drawable.width) + width = pTile->drawable.width - xoffset; + + BitBlt (pGCPriv->hdcMem, + iX, fullY1, + width, 1, + hdcTile, + xoffset, + (fullY1 - (pDrawable->y + (pGC->patOrg.y % pTile->drawable.height) - pTile->drawable.height)) % pTile->drawable.height, + g_copyROP[pGC->alu]); + } + } + + /* Push the tile pixmap out of the memory HDC */ + SelectObject (hdcTile, hbmpOrig); + + /* Delete the tile */ + DeleteDC (hdcTile); break; default: - FatalError ("winFillSpans - DRAWABLE_PIXMAP - Unknown " - "fillStyle\n"); + ErrorF ("winFillSpans - DRAWABLE_PIXMAP - Unknown fillStyle\n"); break; } + + /* Reset clip region */ + SelectClipRgn (pGCPriv->hdcMem, NULL); + + /* Push the drawable pixmap out of the GC HDC */ + SelectObject (pGCPriv->hdcMem, hbmpOrig); break; - + case DRAWABLE_WINDOW: + + SelectClipRgn (pGCPriv->hdc, combined); + DeleteObject (combined); + combined = NULL; + /* Branch on fill style */ switch (pGC->fillStyle) { case FillSolid: - ErrorF ("\nwinFillSpans - DRAWABLE_WINDOW - FillSolid\n\n"); - /* Enumerate spans */ - for (iSpan = 0; iSpan < iSpans; ++iSpan) + ROP16 (pGCPriv->hdc, pGC->alu); + + if (pDrawable->depth == 1) + { + if (pGC->fgPixel == 0) + hPenOrig = SelectObject (pGCPriv->hdc, + GetStockObject (BLACK_PEN)); + else + hPenOrig = SelectObject (pGCPriv->hdc, + GetStockObject (WHITE_PEN)); + } + else + { + fg = pGC->fgPixel; + TRANSLATE_COLOR (fg); + hPen = CreatePen (PS_SOLID, 0, fg); + hPenOrig = SelectObject (pGCPriv->hdc, hPen); + } + + while (iSpans--) { - /* Get pointers to the current span location and width */ - pPoint = pPoints + iSpan; - piWidth = piWidths + iSpan; - - /* Display some useful information */ - ErrorF ("(%dx%dx%d) (%d,%d) fg: %d bg: %d w: %d\n", - pDrawable->width, pDrawable->height, pDrawable->depth, - pPoint->x, pPoint->y, - pGC->fgPixel, pGC->bgPixel, - *piWidth); - - /* Draw the requested line */ - MoveToEx (pGCPriv->hdc, pPoint->x, pPoint->y, NULL); - LineTo (pGCPriv->hdc, pPoint->x + *piWidth, pPoint->y); + fullX1 = pPoints->x; + fullY1 = pPoints->y; + fullX2 = fullX1 + (int) *piWidths; + pPoints++; + piWidths++; + + if (fullY1 < extentY1 || extentY2 <= fullY1) + continue; + + if (fullX1 < extentX1) + fullX1 = extentX1; + if (fullX2 > extentX2) + fullX2 = extentX2; + + if (fullX1 >= fullX2) + continue; + + MoveToEx (pGCPriv->hdc, fullX1, fullY1, NULL); + LineTo (pGCPriv->hdc, fullX2, fullY1); } + + SetROP2 (pGCPriv->hdc, R2_COPYPEN); + + /* Give back the Brush */ + SelectObject (pGCPriv->hdc, hPenOrig); + + if (pDrawable->depth != 1) + DeleteObject (hPen); + break; + + case FillOpaqueStippled: + + pStipple = pGC->stipple; + pStipplePriv = winGetPixmapPriv (pStipple); + + /* Create a device-dependent bitmap for the stipple */ + hBitmap = CreateDIBitmap (pGCPriv->hdc, + (BITMAPINFOHEADER *)pStipplePriv->pbmih, + CBM_INIT, + pStipplePriv->pbBits, + (BITMAPINFO *)pStipplePriv->pbmih, + DIB_RGB_COLORS); + + /* Create a memory DC to hold the stipple */ + hdcStipple = CreateCompatibleDC (pGCPriv->hdc); + + /* Select the stipple bitmap into the stipple DC */ + hbmpOrigStipple = SelectObject (hdcStipple, hBitmap); + if (hbmpOrigStipple == NULL) + FatalError ("winFillSpans () - DRAWABLE_PIXMAP - FillStippled - " + "SelectObject () failed on hbmpOrigStipple\n"); + + /* Make a temporary copy of the foreground and background colors */ + bg = pGC->bgPixel; + fg = pGC->fgPixel; + + /* Translate the depth-dependent colors to Win32 COLORREFs */ + TRANSLATE_COLOR (fg); + TRANSLATE_COLOR (bg); + SetTextColor (pGCPriv->hdc, fg); + SetBkColor (pGCPriv->hdc, bg); + + while (iSpans--) + { + int width = pStipple->drawable.width; + fullX1 = pPoints->x; + fullY1 = pPoints->y; + fullX2 = fullX1 + (int) *piWidths; + pPoints++; + piWidths++; + + if (fullY1 < extentY1 || extentY2 <= fullY1) + continue; + + if (fullX1 < extentX1) + fullX1 = extentX1; + if (fullX2 > extentX2) + fullX2 = extentX2; + + if (fullX1 >= fullX2) + continue; + + for (iX = fullX1; iX < fullX2; iX += width) + { + int xoffset; + + if ((iX + pStipple->drawable.width) > fullX2) + width = fullX2 - iX; + else + width = pStipple->drawable.width; + + if (iX == fullX1) + xoffset = (fullX1 - (pDrawable->x + (pGC->patOrg.x % pStipple->drawable.width) - pStipple->drawable.width)) % pStipple->drawable.width; + else + xoffset = 0; + + if (xoffset + width > pStipple->drawable.width) + width = pStipple->drawable.width - xoffset; + + BitBlt (pGCPriv->hdc, + iX, fullY1, + width, 1, + hdcStipple, + xoffset, + (fullY1 - (pDrawable->y + (pGC->patOrg.y % pStipple->drawable.height) - pStipple->drawable.height)) % pStipple->drawable.height, + g_copyROP[pGC->alu]); + } + } + + /* Clear the stipple HDC */ + SelectObject (hdcStipple, hbmpOrigStipple); + DeleteDC (hdcStipple); + + /* Delete the device dependent stipple bitmap */ + DeleteObject (hBitmap); + break; case FillStippled: - FatalError ("winFillSpans - DRAWABLE_WINDOW - FillStippled\n\n"); + pStipple = pGC->stipple; + pStipplePriv = winGetPixmapPriv (pStipple); + + /* Create a device-dependent bitmap for the stipple */ + hBitmap = CreateDIBitmap (pGCPriv->hdcMem, + (BITMAPINFOHEADER *)pStipplePriv->pbmih, + CBM_INIT, + pStipplePriv->pbBits, + (BITMAPINFO *)pStipplePriv->pbmih, + DIB_RGB_COLORS); + + /* Create a memory DC to hold the stipple */ + hdcStipple = CreateCompatibleDC (pGCPriv->hdc); + + /* Select the stipple bitmap into the stipple DC */ + hbmpOrigStipple = SelectObject (hdcStipple, hBitmap); + if (hbmpOrigStipple == NULL) + FatalError ("winFillSpans () - DRAWABLE_PIXMAP - FillStippled - " + "SelectObject () failed on hbmpOrigStipple\n"); + + /* Make a temporary copy of the foreground and background colors */ + bg = pGC->bgPixel; + fg = pGC->fgPixel; + + /* Translate the depth-dependent colors to Win32 COLORREFs */ + TRANSLATE_COLOR (fg); + TRANSLATE_COLOR (bg); + + /* this is fudgy, we should only invert on the last one + * We need to get the black/white pixels right in the + * colormap. But yeah ! it's working.. + */ + if (pGC->bgPixel != -1 && pGC->fgPixel != -1) + { + SetTextColor (pGCPriv->hdc, fg); + SetBkColor (pGCPriv->hdc, bg); + BitBlt (hdcStipple, + 0, 0, + pStipple->drawable.width, pStipple->drawable.height, + hdcStipple, + 0,0, + 0x330008); + } + else if (pGC->bgPixel == -1) + { + SetTextColor (pGCPriv->hdc, fg); + SetBkMode (pGCPriv->hdc, TRANSPARENT); + BitBlt (hdcStipple, + 0, 0, + pStipple->drawable.width, pStipple->drawable.height, + hdcStipple, + 0,0, + 0x330008); + } + else if (pGC->fgPixel == -1) + { + SetTextColor (pGCPriv->hdc, bg); + SetBkMode (pGCPriv->hdc, TRANSPARENT); +#if 0 + BitBlt (hdcStipple, + 0, 0, + pStipple->drawable.width, pStipple->drawable.height, + hdcStipple, + 0, 0, + 0x330008); +#endif + } + + while (iSpans--) + { + int width = pStipple->drawable.width; + fullX1 = pPoints->x; + fullY1 = pPoints->y; + fullX2 = fullX1 + (int) *piWidths; + pPoints++; + piWidths++; + + if (fullY1 < extentY1 || extentY2 <= fullY1) + continue; + + if (fullX1 < extentX1) + fullX1 = extentX1; + if (fullX2 > extentX2) + fullX2 = extentX2; + + if (fullX1 >= fullX2) + continue; + + for (iX = fullX1; iX < fullX2; iX += width) + { + int xoffset; + + if ((iX + pStipple->drawable.width) > fullX2) + width = fullX2 - iX; + else + width = pStipple->drawable.width; + + if (iX == fullX1) + xoffset = (fullX1 - (pDrawable->x + (pGC->patOrg.x % pStipple->drawable.width) - pStipple->drawable.width)) % pStipple->drawable.width; + else + xoffset = 0; + + if (xoffset + width > pStipple->drawable.width) + width = pStipple->drawable.width - xoffset; + + BitBlt (pGCPriv->hdc, + iX, fullY1, + width, 1, + hdcStipple, + xoffset, + (fullY1 - (pDrawable->y + (pGC->patOrg.y % pStipple->drawable.height) - pStipple->drawable.height)) % pStipple->drawable.height, + g_copyROP[pGC->alu]); + } + } + + /* Clear the stipple HDC */ + SelectObject (hdcStipple, hbmpOrigStipple); + DeleteDC (hdcStipple); + + /* Delete the device dependent stipple bitmap */ + DeleteObject (hBitmap); + + /* Restore the background mode */ + SetBkMode (pGCPriv->hdc, OPAQUE); break; case FillTiled: - ErrorF ("\nwinFillSpans - DRAWABLE_WINDOW - FillTiled\n\n"); /* Get a pixmap pointer from the tile pointer, and fetch privates */ pTile = (PixmapPtr) pGC->tile.pixmap; @@ -402,136 +759,105 @@ winFillSpansNativeGDI (DrawablePtr pDrawable, hbmpOrig = SelectObject (pGCPriv->hdcMem, pTilePriv->hBitmap); if (hbmpOrig == NULL) FatalError ("winFillSpans - DRAWABLE_WINDOW - FillTiled - " - "SelectObject () failed on pTilePric->hBitmap\n"); + "SelectObject () failed on pTilePriv->hBitmap\n"); - /* Enumerate spans */ - for (iSpan = 0; iSpan < iSpans; ++iSpan) + while (iSpans--) { - /* Get pointers to the current span location and width */ - pPoint = pPoints + iSpan; - piWidth = piWidths + iSpan; - - for (iX = 0; iX < *piWidth; iX += pTile->drawable.width) - { - /* Blit the tile to the screen, one line at a time */ + int width = pTile->drawable.width; + fullX1 = pPoints->x; + fullY1 = pPoints->y; + fullX2 = fullX1 + (int) *piWidths; + pPoints++; + piWidths++; + + if (fullY1 < extentY1 || extentY2 <= fullY1) + continue; + + if (fullX1 < extentX1) + fullX1 = extentX1; + if (fullX2 > extentX2) + fullX2 = extentX2; + + if (fullX1 >= fullX2) + continue; + + for (iX = fullX1; iX < fullX2; iX += width) + { + int xoffset; + + if ((iX + pTile->drawable.width) > fullX2) + width = fullX2 - iX; + else + width = pTile->drawable.width; + + if (iX == fullX1) + xoffset = (fullX1 - (pDrawable->x + (pGC->patOrg.x % pTile->drawable.width) - pTile->drawable.width)) % pTile->drawable.width; + else + xoffset = 0; + + if (xoffset + width > pTile->drawable.width) + width = pTile->drawable.width - xoffset; + BitBlt (pGCPriv->hdc, - pPoint->x + iX, pPoint->y, - pTile->drawable.width, 1, + iX, fullY1, + width, 1, pGCPriv->hdcMem, - 0, pPoint->y % pTile->drawable.height, - SRCCOPY); + xoffset, + (fullY1 - (pDrawable->y + (pGC->patOrg.y % pTile->drawable.height) - pTile->drawable.height)) % pTile->drawable.height, + g_copyROP[pGC->alu]); } } - - /* Push the drawable pixmap out of the GC HDC */ - SelectObject (pGCPriv->hdcMem, hbmpOrig); - -#if 0 - DEBUG_MSG("Completed tile fill"); -#endif - break; - case FillOpaqueStippled: - FatalError ("winFillSpans - DRAWABLE_WINDOW - " - "OpaqueStippled\n"); + /* Push the tile pixmap out of the memory HDC */ + SelectObject (pGCPriv->hdcMem, hbmpOrig); break; default: - FatalError ("winFillSpans - DRAWABLE_WINDOW - Unknown " - "fillStyle\n"); - } - - /* Branch on the raster operation type */ - switch (pGC->alu) - { - case GXclear: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXclear\n"); - break; - case GXand: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXand\n"); - break; - case GXandReverse: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXandReverse\n"); - break; - case GXcopy: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXcopy\n"); - break; - case GXandInverted: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXandInverted\n"); - break; - case GXnoop: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXnoop\n"); - break; - case GXxor: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXxor\n"); - break; - case GXor: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXor\n"); - break; - case GXnor: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXnor\n"); - break; - case GXequiv: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXequiv\n"); - break; - case GXinvert: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXinvert\n"); - break; - case GXorReverse: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXorReverse\n"); - break; - case GXcopyInverted: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXcopyInverted\n"); - break; - case GXorInverted: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXorInverted\n"); - break; - case GXnand: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXnand\n"); - break; - case GXset: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - GXset\n"); - break; - default: - ErrorF ("winFillSpans - DRAWABLE_WINDOW - Unknown ROP\n"); + ErrorF ("winFillSpans - DRAWABLE_WINDOW - Unknown fillStyle\n"); break; } + + /* Reset clip region */ + SelectClipRgn (pGCPriv->hdc, NULL); break; - - case UNDRAWABLE_WINDOW: - FatalError ("winFillSpans - UNDRAWABLE_WINDOW\n\n"); + case UNDRAWABLE_WINDOW: + /* UNDRAWABLE_WINDOW doesn't appear to get called when running xterm */ switch (pGC->fillStyle) { case FillSolid: - ErrorF ("\nwinFillSpans - UNDRAWABLE_WINDOW - FillSolid\n\n"); + ErrorF ("winFillSpans - UNDRAWABLE_WINDOW - FillSolid - " + "Unimplemented\n"); break; case FillStippled: - ErrorF ("\nwinFillSpans - UNDRAWABLE_WINDOW - FillStippled\n\n"); + ErrorF ("winFillSpans - UNDRAWABLE_WINDOW - FillStippled - " + "Unimplemented\n"); break; case FillTiled: - ErrorF ("\nwinFillSpans - UNDRAWABLE_WINDOW - FillTiled\n\n"); + ErrorF ("winFillSpans - UNDRAWABLE_WINDOW - FillTiled - " + "Unimplemented\n"); break; case FillOpaqueStippled: - FatalError ("winFillSpans () - UNDRAWABLE_WINDOW - " - "OpaqueStippled\n"); + ErrorF ("winFillSpans - UNDRAWABLE_WINDOW - OpaqueStippled - " + "Unimplemented\n"); break; default: - FatalError ("winFillSpans () - UNDRAWABLE_WINDOW - Unknown " - "fillStyle\n"); + ErrorF ("winFillSpans - UNDRAWABLE_WINDOW - Unknown fillStyle\n"); + break; } break; case DRAWABLE_BUFFER: - FatalError ("winFillSpansNativeGDI - DRAWABLE_BUFFER\n"); + /* DRAWABLE_BUFFER seems to be undocumented. */ + ErrorF ("winFillSpans - DRAWABLE_BUFFER - Unimplemented\n"); break; default: - FatalError ("winFillSpansNativeGDI - Unknown drawable type\n"); + ErrorF ("winFillSpans - Unknown drawable type\n"); break; } } diff --git a/hw/xwin/winfont.c b/hw/xwin/winfont.c index b249d8643..97bd7967b 100644 --- a/hw/xwin/winfont.c +++ b/hw/xwin/winfont.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winfont.c,v 1.2 2001/06/04 13:04:41 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winfont.c,v 1.3 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" @@ -36,7 +36,9 @@ Bool winRealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont) { +#if CYGDEBUG ErrorF ("winRealizeFont()\n"); +#endif return TRUE; } @@ -45,6 +47,8 @@ winRealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont) Bool winUnrealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont) { +#if CYGDEBUG ErrorF ("winUnrealizeFont()\n"); +#endif return TRUE; } diff --git a/hw/xwin/wingc.c b/hw/xwin/wingc.c index 6ad58d8ed..a4e2a53cb 100644 --- a/hw/xwin/wingc.c +++ b/hw/xwin/wingc.c @@ -27,9 +27,11 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/wingc.c,v 1.10 2001/10/30 15:39:09 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/wingc.c,v 1.11 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" +void +winPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable, int dx, int dy, int xOrg, int yOrg); #if 0 /* GC Handling Routines */ @@ -45,8 +47,8 @@ const GCFuncs winGCFuncs = { #else const GCFuncs winGCFuncs = { winValidateGCNativeGDI, - winChangeGCNativeGDI, - winCopyGCNativeGDI, + miChangeGC, + miCopyGC, winDestroyGCNativeGDI, miChangeClip, miDestroyClip, @@ -73,9 +75,14 @@ const GCOps winGCOps = { miPolyText16, miImageText8, miImageText16, +#if 0 + winImageGlyphBltNativeGDI, + winPolyGlyphBltNativeGDI, +#else miImageGlyphBlt, miPolyGlyphBlt, - miPushPixels +#endif + winPushPixels #ifdef NEED_LINEHELPER ,NULL #endif @@ -91,23 +98,21 @@ winCreateGCNativeGDI (GCPtr pGC) winPrivGCPtr pGCPriv = NULL; winPrivScreenPtr pScreenPriv = NULL; - ErrorF ("winCreateGCNativeGDI () depth: %d\n", +#if 0 + ErrorF ("winCreateGCNativeGDI - depth: %d\n", pGC->depth); +#endif pGC->clientClip = NULL; pGC->clientClipType = CT_NONE; + pGC->freeCompClip = FALSE; + pGC->pCompositeClip = 0; pGC->ops = (GCOps *) &winGCOps; pGC->funcs = (GCFuncs *) &winGCFuncs; - /* - * Setting miTranslate to 1 causes the coordinates passed to - * FillSpans, GetSpans, and SetSpans to be screen relative, rather - * than drawable relative. - * - * miTranslate was set to 0 prior to 2001-08-17. - */ - pGC->miTranslate = 1; + /* We want all coordinates passed to spans functions to be screen relative */ + pGC->miTranslate = TRUE; /* Allocate privates for this GC */ pGCPriv = winGetGCPriv (pGC); @@ -117,9 +122,9 @@ winCreateGCNativeGDI (GCPtr pGC) return FALSE; } - /* Copy the screen DC to the local privates */ + /* Create a new screen DC for the display window */ pScreenPriv = winGetScreenPriv (pGC->pScreen); - pGCPriv->hdc = pScreenPriv->hdcScreen; + pGCPriv->hdc = GetDC (pScreenPriv->hwndScreen); /* Allocate a memory DC for the GC */ pGCPriv->hdcMem = CreateCompatibleDC (pGCPriv->hdc); @@ -132,7 +137,7 @@ winCreateGCNativeGDI (GCPtr pGC) void winChangeGCNativeGDI (GCPtr pGC, unsigned long ulChanges) { -#if CYGDEBUG +#if 0 ErrorF ("winChangeGCNativeGDI () - Doing nothing\n"); #endif } @@ -143,225 +148,11 @@ winValidateGCNativeGDI (GCPtr pGC, unsigned long ulChanges, DrawablePtr pDrawable) { - winGCPriv(pGC); - HBITMAP hbmpOrig = NULL; - PixmapPtr pPixmap = NULL; - winPrivPixmapPtr pPixmapPriv = NULL; - RGBQUAD rgbColors[2] = {{0, 0, 0, 0}, {0, 0, 0, 0}}; - PixmapPtr pStipple = NULL; - winPrivPixmapPtr pStipplePriv = NULL; - int i; - DEBUG_FN_NAME("winValidateGC"); - DEBUGVARS; - DEBUGPROC_MSG; - - /* Branch on drawable type */ - switch (pDrawable->type) - { - case DRAWABLE_PIXMAP: - /* Branch on the fill style */ - switch (pGC->fillStyle) - { - case FillSolid: - ErrorF ("winValidateGC - DRAWABLE_PIXMAP - FillSolid\n"); - - /* Select a stock pen */ - if (pDrawable->depth == 1 && pGC->fgPixel) - { - ErrorF ("winValidateGC - Selecting WHITE_PEN\n"); - SelectObject (pGCPriv->hdcMem, GetStockObject (WHITE_PEN)); - } - else if (pDrawable->depth == 1 && !pGC->fgPixel) - { - ErrorF ("winValidateGC - Selecting BLACK_PEN\n"); - SelectObject (pGCPriv->hdcMem, GetStockObject (BLACK_PEN)); - } - else if (pGC->fgPixel) - { - ErrorF ("winValidateGC - Selecting custom pen: %d\n", - pGC->fgPixel); - /* - * FIXME: So far I've only seen a white pen selected here. - */ -#if 1 - SelectObject (pGCPriv->hdcMem, GetStockObject (WHITE_PEN)); -#else - /* FIXME: This leaks a pen */ - SelectObject (pGCPriv->hdcMem, - CreatePen (PS_SOLID, 0, pGC->fgPixel)); -#endif - } - else - { - ErrorF ("winValidateGC - Selecting BLACK_PEN\n"); - SelectObject (pGCPriv->hdcMem, GetStockObject (BLACK_PEN)); - } - break; - - case FillStippled: - ErrorF ("winValidateGC - DRAWABLE_PIXMAP - FillStippled\n"); - /* - * NOTE: Setting the brush color has no effect on DIB fills. - * You need to set the stipple bitmap's color table instead. - */ -#if 1 - /* Pick the white color index */ - if (pGC->fgPixel) - i = 1; - else - i = 0; - - /* Set the white color, black is default */ - rgbColors[i].rgbRed = 255; - rgbColors[i].rgbGreen = 255; - rgbColors[i].rgbBlue = 255; - - /* Get stipple and privates pointers */ - pStipple = pGC->stipple; - pStipplePriv = winGetPixmapPriv (pStipple); - - /* Select the stipple bitmap */ - hbmpOrig = SelectObject (pGCPriv->hdcMem, pStipplePriv->hBitmap); - - /* Set the stipple color table */ - SetDIBColorTable (pGCPriv->hdcMem, 0, 2, rgbColors); - - /* Pop the stipple out of the hdc */ - SelectObject (pGCPriv->hdcMem, hbmpOrig); - -#else - /* Set the foreground color for the stipple fill */ - if (pGC->fgPixel == 0x1) - { - SetTextColor (pGCPriv->hdcMem, RGB(0x00, 0x00, 0x00)); - } - else if (pGC->fgPixel == 0xFFFF) - { - SetTextColor (pGCPriv->hdcMem, RGB(0xFF, 0xFF, 0xFF)); - } - else - { - SetTextColor (pGCPriv->hdcMem, RGB(0x00, 0x00, 0x00)); - } - SetBkColor (pGCPriv->hdcMem, RGB(0x00, 0x00, 0x00)); -#endif - break; - - case FillOpaqueStippled: - FatalError ("winValidateGC - DRAWABLE_PIXMAP - " - "FillOpaqueStippled\n"); - break; - - case FillTiled: - FatalError ("winValidateGC - DRAWABLE_PIXMAP - FillTiled\n"); - break; - - default: - FatalError ("winValidateGC - DRAWABLE_PIXMAP - Unknown fill " - "style\n"); - break; - } - break; - - case DRAWABLE_WINDOW: - /* Branch on the fill style */ - switch (pGC->fillStyle) - { - case FillTiled: - ErrorF ("winValidateGC - DRAWABLE_WINDOW - FillTiled\n"); - /* - * Do nothing here for now. Select the tile bitmap into the - * appropriate DC in the drawing function. - */ - - /* - * BEGIN REMOVE - Visual verification only. - */ - /* Get pixmap and privates pointers for the tile */ - pPixmap = pGC->tile.pixmap; - pPixmapPriv = winGetPixmapPriv (pPixmap); - - /* Push the tile into the GC's DC */ - hbmpOrig = SelectObject (pGCPriv->hdcMem, pPixmapPriv->hBitmap); - if (hbmpOrig == NULL) - FatalError ("winValidateGC - DRAWABLE_WINDOW - FillTiled - " - "SelectObject () failed on pPixmapPriv->hBitmap\n"); - - /* Blit the tile to a remote area of the screen */ - BitBlt (pGCPriv->hdc, - 64, 64, - pGC->tile.pixmap->drawable.width, - pGC->tile.pixmap->drawable.height, - pGCPriv->hdcMem, - 0, 0, - SRCCOPY); - DEBUG_MSG ("Blitted the tile to a remote area of the screen"); - - /* Pop the tile out of the GC's DC */ - SelectObject (pGCPriv->hdcMem, hbmpOrig); - /* - * END REMOVE - Visual verification only. - */ - break; - - case FillStippled: - FatalError ("winValidateGC - DRAWABLE_WINDOW - FillStippled\n"); - break; - - case FillOpaqueStippled: - FatalError ("winValidateGC - DRAWABLE_WINDOW - " - "FillOpaqueStippled\n"); - break; - - case FillSolid: - ErrorF ("winValidateGC - DRAWABLE_WINDOW - FillSolid\n"); - - /* Select a stock pen */ - if (pDrawable->depth == 1 && pGC->fgPixel) - { - ErrorF ("winValidateGC - Selecting WHITE_PEN\n"); - SelectObject (pGCPriv->hdc, GetStockObject (WHITE_PEN)); - } - else if (pDrawable->depth == 1 && !pGC->fgPixel) - { - ErrorF ("winValidateGC - Selecting BLACK_PEN\n"); - SelectObject (pGCPriv->hdc, GetStockObject (BLACK_PEN)); - } - else if (pGC->fgPixel) - { - ErrorF ("winValidateGC - Selecting custom pen: %d\n", - pGC->fgPixel); - /* - * FIXME: So far I've only seen a white pen selected here. - */ - SelectObject (pGCPriv->hdc, GetStockObject (WHITE_PEN)); - } - else - { - ErrorF ("winValidateGC - Selecting BLACK_PEN\n"); - SelectObject (pGCPriv->hdc, GetStockObject (BLACK_PEN)); - } - break; - - default: - FatalError ("winValidateGC - DRAWABLE_WINDOW - Unknown fill " - "style\n"); - break; - } - break; - - case UNDRAWABLE_WINDOW: - ErrorF ("\nwinValidateGC - UNDRAWABLE_WINDOW\n\n"); - break; - - case DRAWABLE_BUFFER: - FatalError ("winValidateGC - DRAWABLE_BUFFER\n"); - break; - - default: - FatalError ("winValidateGC - Unknown drawable type\n"); - break; - } + if ((ulChanges & (GCClipXOrigin | GCClipYOrigin | GCClipMask | GCSubwindowMode)) + || (pDrawable->serialNumber != (pGC->serialNumber & DRAWABLE_SERIAL_BITS))) + { + miComputeCompositeClip (pGC, pDrawable); + } } @@ -378,6 +169,10 @@ void winDestroyGCNativeGDI (GCPtr pGC) { winGCPriv(pGC); + winScreenPriv(pGC->pScreen); + + if (pGC->freeCompClip) + REGION_DESTROY (pGC->pScreen, pGC->pCompositeClip); /* Free the memory DC */ if (pGCPriv->hdcMem != NULL) @@ -386,8 +181,12 @@ winDestroyGCNativeGDI (GCPtr pGC) pGCPriv->hdcMem = NULL; } - /* Invalidate the screen DC pointer */ - pGCPriv->hdc = NULL; + /* Release the screen DC for the display window */ + if (pGCPriv->hdc != NULL) + { + ReleaseDC (pScreenPriv->hwndScreen, pGCPriv->hdc); + pGCPriv->hdc = NULL; + } /* Invalidate the GC privates pointer */ winSetGCPriv (pGC, NULL); diff --git a/hw/xwin/wingetsp.c b/hw/xwin/wingetsp.c index 637debb9e..49ba7f2fb 100644 --- a/hw/xwin/wingetsp.c +++ b/hw/xwin/wingetsp.c @@ -26,8 +26,9 @@ *from the XFree86 Project. * * Authors: Harold L Hunt II + * Alan Hourihane <alanh@fairlite.demon.co.uk> */ -/* $XFree86: xc/programs/Xserver/hw/xwin/wingetsp.c,v 1.7 2001/11/01 12:19:40 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/wingetsp.c,v 1.8 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" @@ -46,107 +47,132 @@ winGetSpansNativeGDI (DrawablePtr pDrawable, DDXPointPtr pPoint = NULL; int *piWidth = NULL; char *pDst = pDsts; - int iBytesToCopy; - HBITMAP hbmpWindow, hbmpOrig; + HBITMAP hbmpWindow, hbmpOrig, hbmpOrig1; BYTE *pbWindow = NULL; - HDC hdcMem; + HDC hdcMem, hdcMem1; ScreenPtr pScreen = pDrawable->pScreen; winScreenPriv(pScreen); - int iByteWidth; /* Branch on the drawable type */ switch (pDrawable->type) { case DRAWABLE_PIXMAP: +#if 0 ErrorF ("winGetSpans - DRAWABLE_PIXMAP %08x\n", pDrawable); +#endif pPixmap = (PixmapPtr) pDrawable; pPixmapPriv = winGetPixmapPriv (pPixmap); + /* Open a memory HDC */ + hdcMem1 = CreateCompatibleDC (NULL); + hdcMem = CreateCompatibleDC (NULL); + + /* Select the drawable pixmap into a DC */ + hbmpOrig1 = SelectObject (hdcMem1, pPixmapPriv->hBitmap); + + if (hbmpOrig1 == NULL) + FatalError ("winGetSpans - DRAWABLE_PIXMAP - SelectObject () " + "failed on pPixmapPriv->hBitmap\n"); + /* Loop through spans */ for (iSpan = 0; iSpan < iSpans; ++iSpan) { pPoint = pPoints + iSpan; piWidth = piWidths + iSpan; - - iBytesToCopy = PixmapBytePad (*piWidth, pDrawable->depth); + + hbmpWindow = winCreateDIBNativeGDI (*piWidth, 1, + pDrawable->depth, + &pbWindow, + NULL); + + hbmpOrig = SelectObject (hdcMem, hbmpWindow); + + /* Transfer the window bits to the window bitmap */ + BitBlt (hdcMem, + 0, 0, + *piWidth, 1, + hdcMem1, + pPoint->x, pPoint->y, + SRCCOPY); memcpy (pDst, - pPixmapPriv->pbBits - + pPixmapPriv->dwScanlineBytes * pPoint->y, - iBytesToCopy); + (char*) pbWindow, + PixmapBytePad (*piWidth, pDrawable->depth)); + + /* Pop the window bitmap out of the HDC and delete the bitmap */ + SelectObject (hdcMem, hbmpOrig); + DeleteObject (hbmpWindow); +#if 0 ErrorF ("(%dx%dx%d) (%d,%d) w: %d\n", pDrawable->width, pDrawable->height, pDrawable->depth, pPoint->x, pPoint->y, *piWidth); +#endif /* Calculate offset of next bit destination */ - pDst += 4 * ((*piWidth + 31) / 32); + pDst += PixmapBytePad (*piWidth, pDrawable->depth); } + + /* Pop the pixmap's bitmap out of the HDC */ + SelectObject (hdcMem1, hbmpOrig1); + + /* Delete the HDCs */ + DeleteDC (hdcMem1); + DeleteDC (hdcMem); break; case DRAWABLE_WINDOW: +#if 0 ErrorF ("winGetSpans - DRAWABLE_WINDOW\n"); - - /* - * FIXME: Making huge assumption here that we are copying the - * area behind where the cursor will be displayed. We already - * know the size of the cursor, so this works, for now. - */ - - /* Create a bitmap to blit the window data to */ - hbmpWindow = winCreateDIBNativeGDI (*piWidths, - *piWidths, - pDrawable->depth, - &pbWindow, - NULL); +#endif /* Open a memory HDC */ hdcMem = CreateCompatibleDC (NULL); - /* Select the window bitmap */ - hbmpOrig = SelectObject (hdcMem, hbmpWindow); - - /* Transfer the window bits to the window bitmap */ - BitBlt (hdcMem, - 0, 0, - *piWidths, *piWidths, /* FIXME: Assuming square region */ - pScreenPriv->hdcScreen, - pPoints->x, pPoints->y, - SRCCOPY); - - /* Pop the window bitmap out of the HDC */ - SelectObject (hdcMem, hbmpOrig); - - /* Delete the memory HDC */ - DeleteDC (hdcMem); - hdcMem = NULL; - - iByteWidth = PixmapBytePad (*piWidths, pDrawable->depth); - /* Loop through spans */ for (iSpan = 0; iSpan < iSpans; ++iSpan) { pPoint = pPoints + iSpan; piWidth = piWidths + iSpan; - iBytesToCopy = PixmapBytePad (*piWidth, pDrawable->depth); + hbmpWindow = winCreateDIBNativeGDI (*piWidth, 1, + pDrawable->depth, + &pbWindow, + NULL); + + hbmpOrig = SelectObject (hdcMem, hbmpWindow); + + /* Transfer the window bits to the window bitmap */ + BitBlt (hdcMem, + 0, 0, + *piWidth, 1, + pScreenPriv->hdcScreen, + pPoint->x, pPoint->y, + SRCCOPY); memcpy (pDst, - pbWindow + iByteWidth * (pPoint->y - pPoints->y), - iBytesToCopy); - + (char*) pbWindow, + PixmapBytePad (*piWidth, pDrawable->depth)); + + /* Pop the window bitmap out of the HDC */ + SelectObject (hdcMem, hbmpOrig); + + DeleteObject (hbmpWindow); + +#if 0 ErrorF ("(%dx%dx%d) (%d,%d) w: %d\n", pDrawable->width, pDrawable->height, pDrawable->depth, pPoint->x, pPoint->y, *piWidth); +#endif /* Calculate offset of next bit destination */ - pDst += 4 * ((*piWidth + 31) / 32); + pDst += PixmapBytePad (*piWidth, pDrawable->depth); } /* Delete the window bitmap */ - DeleteObject (hbmpWindow); + DeleteDC (hdcMem); break; case UNDRAWABLE_WINDOW: diff --git a/hw/xwin/winkeybd.c b/hw/xwin/winkeybd.c index 20df053c2..95f245e57 100644 --- a/hw/xwin/winkeybd.c +++ b/hw/xwin/winkeybd.c @@ -30,7 +30,7 @@ * Peter Busch * Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winkeybd.c,v 1.12 2002/10/17 08:18:22 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winkeybd.c,v 1.13 2003/07/29 21:25:17 dawes Exp $ */ #include "win.h" @@ -649,31 +649,23 @@ void winKeybdReleaseKeys () { #if !WIN_NEW_KEYBOARD_SUPPORT -#if 0 /* Old function that just pops modifiers */ - /* Verify that the mi input system has been initialized */ - if (g_fdMessageQueue == WIN_FD_INVALID) - return; - - winSendKeyEvent (KEY_Alt, FALSE); - winSendKeyEvent (KEY_AltLang, FALSE); - winSendKeyEvent (KEY_LCtrl, FALSE); - winSendKeyEvent (KEY_RCtrl, FALSE); - winSendKeyEvent (KEY_ShiftL, FALSE); - winSendKeyEvent (KEY_ShiftR, FALSE); -#else /* New function that pops all keys */ int i; /* Verify that the mi input system has been initialized */ if (g_fdMessageQueue == WIN_FD_INVALID) return; - /* Pop any pressed keys */ + /* Loop through all keys */ for (i = 0; i < NUM_KEYCODES; ++i) { - if (g_winKeyState[i]) winSendKeyEvent (i, FALSE); + /* Pop key if pressed */ + if (g_winKeyState[i]) + winSendKeyEvent (i, FALSE); + + /* Reset pressed flag for keys */ + g_winKeyState[i] = FALSE; } #endif -#endif } diff --git a/hw/xwin/winmsg.c b/hw/xwin/winmsg.c index 35342c359..ce8ac4199 100644 --- a/hw/xwin/winmsg.c +++ b/hw/xwin/winmsg.c @@ -27,7 +27,7 @@ * * Authors: Alexander Gottwald */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winmsg.c,v 1.1 2002/10/17 08:18:22 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winmsg.c,v 1.2 2003/10/02 13:30:10 eich Exp $ */ #include "win.h" #include "winmsg.h" @@ -45,26 +45,7 @@ void winVMsg (int scrnIndex, MessageType type, int verb, const char *format, va_list ap) { - const char *prefix = NULL; - - if (verb && verb > VERBOSE_LEVEL) - return; - -#undef __msg -#define __msg(name,string) case name: prefix = string; break; -#undef _msg -#define _msg(name,string) __msg(name,string) - switch (type) - { - MESSAGE_STRINGS default:prefix = NULL; - break; - } -#undef __msg -#undef _msg - - if (prefix != NULL) - ErrorF ("%s ", prefix); - VErrorF (format, ap); + LogVMessageVerb(type, verb, format, ap); } @@ -73,7 +54,7 @@ winDrvMsg (int scrnIndex, MessageType type, const char *format, ...) { va_list ap; va_start (ap, format); - winVMsg (scrnIndex, type, 0, format, ap); + LogVMessageVerb(type, 0, format, ap); va_end (ap); } @@ -83,7 +64,7 @@ winMsg (MessageType type, const char *format, ...) { va_list ap; va_start (ap, format); - winVMsg (0, type, 0, format, ap); + LogVMessageVerb(type, 0, format, ap); va_end (ap); } @@ -94,7 +75,7 @@ winDrvMsgVerb (int scrnIndex, MessageType type, int verb, const char *format, { va_list ap; va_start (ap, format); - winVMsg (scrnIndex, type, verb, format, ap); + LogVMessageVerb(type, verb, format, ap); va_end (ap); } @@ -104,7 +85,7 @@ winMsgVerb (MessageType type, int verb, const char *format, ...) { va_list ap; va_start (ap, format); - winVMsg (0, type, verb, format, ap); + LogVMessageVerb(type, verb, format, ap); va_end (ap); } @@ -114,6 +95,6 @@ winErrorFVerb (int verb, const char *format, ...) { va_list ap; va_start (ap, format); - winVMsg (0, X_NONE, verb, format, ap); + LogVMessageVerb(X_NONE, verb, format, ap); va_end (ap); } diff --git a/hw/xwin/winmsg.h b/hw/xwin/winmsg.h index c873d4beb..16ec536b0 100644 --- a/hw/xwin/winmsg.h +++ b/hw/xwin/winmsg.h @@ -27,36 +27,11 @@ * * Authors: Alexander Gottwald */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winmsg.h,v 1.1 2002/10/17 08:18:22 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winmsg.h,v 1.2 2003/10/02 13:30:10 eich Exp $ */ #ifndef __WIN_MSG_H__ #define __WIN_MSG_H__ - -#define __msg_name(name,string) name -#define __msg(name,string) __msg_name(name,string) -#define _msg(name,string) __msg(name,string), - -#define MESSAGE_STRINGS \ - _msg(X_PROBED,"(--)" /* Value was probed */)\ - _msg(X_CONFIG,"(**)" /* Value was given in the config file */)\ - _msg(X_DEFAULT,"(==)" /* Value is a default */)\ - _msg(X_CMDLINE,"(++)" /* Value was given on the command line */)\ - _msg(X_NOTICE,"(!!)" /* Notice */) \ - _msg(X_ERROR,"(EE)" /* Error message */) \ - _msg(X_WARNING,"(WW)" /* Warning message */) \ - _msg(X_INFO,"(II)" /* Informational message */) \ - _msg(X_UNKNOWN,"(?""?)" /* Unknown, trigraph fix */) \ - _msg(X_NONE,NULL /* No prefix */) \ - __msg(X_NOT_IMPLEMENTED,"(NI)" /* Not implemented */) - -typedef enum -{ - MESSAGE_STRINGS -} -MessageType; - - /* * Function prototypes */ diff --git a/hw/xwin/winmultiwindowwindow.c b/hw/xwin/winmultiwindowwindow.c index 57d209e2a..15e508659 100644 --- a/hw/xwin/winmultiwindowwindow.c +++ b/hw/xwin/winmultiwindowwindow.c @@ -26,11 +26,22 @@ *from the XFree86 Project. * * Authors: Kensuke Matsuzaki + * Earle F. Philhower, III + * Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winmultiwindowwindow.c,v 1.1 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winmultiwindowwindow.c,v 1.3 2003/10/02 13:30:10 eich Exp $ */ #include "win.h" #include "dixevents.h" +#include "winmultiwindowclass.h" +#include "winprefs.h" + + +/* + * External global variables + */ + +extern HICON g_hiconX; /* @@ -46,31 +57,12 @@ winDestroyWindowsWindow (WindowPtr pWin); static void winUpdateWindowsWindow (WindowPtr pWin); -static XID -winGetWindowID (WindowPtr pWin); - static void -SendConfigureNotify (WindowPtr pWin); - -static -void -winUpdateRgn (WindowPtr pWindow); - -#ifdef SHAPE -static -void -winReshape (WindowPtr pWin); -#endif - - -/* - * Local globals - */ - -static UINT s_nIDPollingMouse = 2; +winFindWindow (pointer value, XID id, pointer cdata); #if 0 -static BOOL s_fMoveByX = FALSE; +static void +winRestackXWindow (WindowPtr pWin, int smode); #endif @@ -78,9 +70,8 @@ static BOOL s_fMoveByX = FALSE; * Constant defines */ +#define MOUSE_POLLING_INTERVAL 500 -#define MOUSE_POLLING_INTERVAL 500 -#define WIN_MULTIWINDOW_SHAPE YES /* * Macros @@ -118,6 +109,7 @@ winCreateWindowMultiWindow (WindowPtr pWin) pWinPriv->hWnd = NULL; pWinPriv->pScreenPriv = winGetScreenPriv(pWin->drawable.pScreen); pWinPriv->fXKilled = FALSE; + pWinPriv->fNeedRestore = FALSE; return fResult; } @@ -191,8 +183,8 @@ winPositionWindowMultiWindow (WindowPtr pWin, int x, int y) iBorder = wBorderWidth (pWin); /* Get the X and Y location of the X window */ - iX = pWin->drawable.x; - iY = pWin->drawable.y; + iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN); + iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN); /* Get the height and width of the X window */ iWidth = pWin->drawable.width; @@ -336,9 +328,10 @@ winMapWindowMultiWindow (WindowPtr pWin) /* Refresh/redisplay the Windows window associated with this X window */ winUpdateWindowsWindow (pWin); -#if WIN_MULTIWINDOW_SHAPE - winReshape (pWin); - winUpdateRgn (pWin); +#ifdef SHAPE + /* Update the Windows window's shape */ + winReshapeMultiWindow (pWin); + winUpdateRgnMultiWindow (pWin); #endif return fResult; @@ -376,6 +369,7 @@ winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib) WindowPtr pPrevWin; UINT uFlags; HWND hInsertAfter; + HWND hWnd = NULL; winWindowPriv(pWin); #if CYGMULTIWINDOW_DEBUG @@ -387,6 +381,9 @@ winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib) winGetScreenPriv(pWin->drawable.pScreen)->RestackWindow (pWin, pOldNextSib); + if (winGetScreenPriv(pWin->drawable.pScreen)->fRestacking) + return; + /* Bail out if no window privates or window handle is invalid */ if (!pWinPriv || !pWinPriv->hWnd) return; @@ -409,6 +406,22 @@ winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib) /* Valid sibling - get handle to insert window after */ hInsertAfter = winGetWindowPriv(pPrevWin)->hWnd; uFlags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE; + + hWnd = GetNextWindow (pWinPriv->hWnd, GW_HWNDPREV); + + do + { + if (GetProp (hWnd, WIN_WINDOW_PROP)) + { + if (hWnd == winGetWindowPriv(pPrevWin)->hWnd) + { + uFlags |= SWP_NOZORDER; + } + break; + } + hWnd = GetNextWindow (hWnd, GW_HWNDPREV); + } + while (hWnd); } else { @@ -427,966 +440,111 @@ winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib) /* - * SetShape - See Porting Layer Definition - p. 42 - */ - -#ifdef SHAPE -void -winSetShapeMultiWindow (WindowPtr pWin) -{ -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winSetShapeMultiWindow - pWin: %08x\n", pWin); -#endif - - /* Call any wrapped SetShape function */ - if (winGetScreenPriv(pWin->drawable.pScreen)->SetShape) - winGetScreenPriv(pWin->drawable.pScreen)->SetShape (pWin); - - /* - * NOTE: We do not currently do anything here. - */ - -#if WIN_MULTIWINDOW_SHAPE - winReshape (pWin); - winUpdateRgn (pWin); -#endif - - return; -} -#endif - - -/* - * winUpdateRgn - Local function to update a Windows window region - */ - -static -void -winUpdateRgn (WindowPtr pWin) -{ -#if 1 - SetWindowRgn (winGetWindowPriv(pWin)->hWnd, - winGetWindowPriv(pWin)->hRgn, TRUE); -#endif -} - - -/* - * winReshape - Computes the composite clipping region for a window + * winCreateWindowsWindow - Create a Windows window associated with an X window */ -#ifdef SHAPE -static -void -winReshape (WindowPtr pWin) +static void +winCreateWindowsWindow (WindowPtr pWin) { - int nRects; - ScreenPtr pScreen = pWin->drawable.pScreen; - RegionRec rrNewShape; - BoxPtr pShape, pRects, pEnd; - HRGN hRgn, hRgnRect; + int iX, iY; + int iWidth; + int iHeight; + int iBorder; + HWND hWnd; + WNDCLASS wc; winWindowPriv(pWin); + HICON hIcon; +#define CLASS_NAME_LENGTH 512 + char pszClass[CLASS_NAME_LENGTH], pszWindowID[12]; + char *res_name, *res_class, *res_role; + static int s_iWindowID = 0; -#if CYGDEBUG - ErrorF ("winReshape ()\n"); +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winCreateWindowsWindow - pWin: %08x\n", pWin); #endif - - /* Bail if the window is the root window */ - if (pWin->parent == NULL) - return; - /* Bail if the window is not top level */ - if (pWin->parent->parent != NULL) - return; - - /* Bail if Windows window handle is invalid */ - if (pWinPriv->hWnd == NULL) - return; + iBorder = wBorderWidth (pWin); - /* Free any existing window region stored in the window privates */ - if (pWinPriv->hRgn != NULL) - { - DeleteObject (pWinPriv->hRgn); - pWinPriv->hRgn = NULL; - } + iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN); + iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN); - /* Bail if the window has no bounding region defined */ - if (!wBoundingShape (pWin)) - return; + iWidth = pWin->drawable.width; + iHeight = pWin->drawable.height; - REGION_INIT(pScreen, &rrNewShape, NullBox, 0); - REGION_COPY(pScreen, &rrNewShape, wBoundingShape(pWin)); - REGION_TRANSLATE(pScreen, - &rrNewShape, - pWin->borderWidth, - pWin->borderWidth); - - nRects = REGION_NUM_RECTS(&rrNewShape); - pShape = REGION_RECTS(&rrNewShape); + /* Load default X icon in case it's not ready yet */ + if (!g_hiconX) + g_hiconX = (HICON)winOverrideDefaultIcon(); - /* Don't do anything if there are no rectangles in the region */ - if (nRects > 0) - { - RECT rcClient; - RECT rcWindow; - int iOffsetX, iOffsetY; - - /* Get client rectangle */ - if (!GetClientRect (pWinPriv->hWnd, &rcClient)) - { - ErrorF ("winReshape - GetClientRect failed, bailing: %d\n", - GetLastError ()); - return; - } - - /* Translate client rectangle coords to screen coords */ - /* NOTE: Only transforms top and left members */ - ClientToScreen (pWinPriv->hWnd, (LPPOINT) &rcClient); - - /* Get window rectangle */ - if (!GetWindowRect (pWinPriv->hWnd, &rcWindow)) - { - ErrorF ("winReshape - GetWindowRect failed, bailing: %d\n", - GetLastError ()); - return; - } - - /* Calculate offset from window upper-left to client upper-left */ - iOffsetX = rcClient.left - rcWindow.left; - iOffsetY = rcClient.top - rcWindow.top; - - /* Create initial Windows region for title bar */ - /* FIXME: Mean, nasty, ugly hack!!! */ - hRgn = CreateRectRgn (0, 0, rcWindow.right, iOffsetY); - if (hRgn == NULL) - { - ErrorF ("winReshape - Initial CreateRectRgn (%d, %d, %d, %d) " - "failed: %d\n", - 0, 0, rcWindow.right, iOffsetY, GetLastError ()); - } - - /* Loop through all rectangles in the X region */ - for (pRects = pShape, pEnd = pShape + nRects; pRects < pEnd; pRects++) - { - /* Create a Windows region for the X rectangle */ - hRgnRect = CreateRectRgn (pRects->x1 + iOffsetX - 1, - pRects->y1 + iOffsetY - 1, - pRects->x2 + iOffsetX - 1, - pRects->y2 + iOffsetY - 1); - if (hRgnRect == NULL) - { - ErrorF ("winReshape - Loop CreateRectRgn (%d, %d, %d, %d) " - "failed: %d\n" - "\tx1: %d x2: %d xOff: %d y1: %d y2: %d yOff: %d\n", - pRects->x1 + iOffsetX - 1, - pRects->y1 + iOffsetY - 1, - pRects->x2 + iOffsetX - 1, - pRects->y2 + iOffsetY - 1, - GetLastError (), - pRects->x1, pRects->x2, iOffsetX, - pRects->y1, pRects->y2, iOffsetY); - } - - /* Merge the Windows region with the accumulated region */ - if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR) - { - ErrorF ("winReshape - CombineRgn () failed: %d\n", - GetLastError ()); - } - - /* Delete the temporary Windows region */ - DeleteObject (hRgnRect); - } - - /* Save a handle to the composite region in the window privates */ - pWinPriv->hRgn = hRgn; - } - - REGION_UNINIT(pScreen, &rrNewShape); + if (!g_hiconX) + g_hiconX = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN)); - return; -} -#endif - - -/* - * winTopLevelWindowProc - Window procedure for all top-level Windows windows. - */ - -LRESULT CALLBACK -winTopLevelWindowProc (HWND hwnd, UINT message, - WPARAM wParam, LPARAM lParam) -{ - POINT ptMouse; - HDC hdcUpdate; - PAINTSTRUCT ps; - WindowPtr pWin = NULL; - winPrivWinPtr pWinPriv = NULL; - ScreenPtr s_pScreen = NULL; - winPrivScreenPtr s_pScreenPriv = NULL; - winScreenInfo *s_pScreenInfo = NULL; - HWND hwndScreen = NULL; - DrawablePtr pDraw = NULL; - int iX, iY, iWidth, iHeight, iBorder; - winWMMessageRec wmMsg; - static Bool s_fTracking = FALSE; - static Bool s_fCursor = TRUE; + /* Try and get the icon from WM_HINTS */ + hIcon = winXIconToHICON (pWin); - /* Check if the Windows window property for our X window pointer is valid */ - if ((pWin = GetProp (hwnd, WIN_WINDOW_PROP)) != NULL) - { - /* Our X window pointer is valid */ - - /* Get pointers to the drawable and the screen */ - pDraw = &pWin->drawable; - s_pScreen = pWin->drawable.pScreen; - - /* Get a pointer to our window privates */ - pWinPriv = winGetWindowPriv(pWin); - - /* Get pointers to our screen privates and screen info */ - s_pScreenPriv = pWinPriv->pScreenPriv; - s_pScreenInfo = s_pScreenPriv->pScreenInfo; - - /* Get the handle for our screen-sized window */ - /* NOTE: This will be going away at some point, right? Harold Hunt - 2003/01/15 */ - hwndScreen = s_pScreenPriv->hwndScreen; - - /* */ - wmMsg.msg = 0; - wmMsg.hwndWindow = hwnd; - wmMsg.iWindow = (Window)GetProp (hwnd, WIN_WID_PROP); - -#if 1 - wmMsg.iX = pWinPriv->iX; - wmMsg.iY = pWinPriv->iY; - wmMsg.iWidth = pWinPriv->iWidth; - wmMsg.iHeight = pWinPriv->iHeight; -#else - wmMsg.iX = pDraw.x; - wmMsg.iY = pDraw.y; - wmMsg.iWidth = pDraw.width; - wmMsg.iHeight = pDraw.height; -#endif - - -#if 0 - /* - * Print some debugging information - */ - - ErrorF ("hWnd %08X\n", hwnd); - ErrorF ("pWin %08X\n", pWin); - ErrorF ("pDraw %08X\n", pDraw); - ErrorF ("\ttype %08X\n", pWin->drawable.type); - ErrorF ("\tclass %08X\n", pWin->drawable.class); - ErrorF ("\tdepth %08X\n", pWin->drawable.depth); - ErrorF ("\tbitsPerPixel %08X\n", pWin->drawable.bitsPerPixel); - ErrorF ("\tid %08X\n", pWin->drawable.id); - ErrorF ("\tx %08X\n", pWin->drawable.x); - ErrorF ("\ty %08X\n", pWin->drawable.y); - ErrorF ("\twidth %08X\n", pWin->drawable.width); - ErrorF ("\thenght %08X\n", pWin->drawable.height); - ErrorF ("\tpScreen %08X\n", pWin->drawable.pScreen); - ErrorF ("\tserialNumber %08X\n", pWin->drawable.serialNumber); - ErrorF ("g_iWindowPrivateIndex %d\n", g_iWindowPrivateIndex); - ErrorF ("pWinPriv %08X\n", pWinPriv); - ErrorF ("s_pScreenPriv %08X\n", s_pScreenPriv); - ErrorF ("s_pScreenInfo %08X\n", s_pScreenInfo); - ErrorF ("hwndScreen %08X\n", hwndScreen); -#endif - } + /* Use default X icon if no icon loaded from WM_HINTS */ + if (!hIcon) + hIcon = g_hiconX; + /* Set standard class name prefix so we can identify window easily */ + strncpy (pszClass, WINDOW_CLASS_X, strlen (WINDOW_CLASS_X)); - - /* Branch on message type */ - switch (message) + if (winMultiWindowGetClassHint (pWin, &res_name, &res_class)) { - case WM_CREATE: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_CREATE\n"); -#endif - - /* */ - SetProp (hwnd, - WIN_WINDOW_PROP, - (HANDLE)((LPCREATESTRUCT) lParam)->lpCreateParams); - - /* */ - SetProp (hwnd, - WIN_WID_PROP, - (HANDLE)winGetWindowID (((LPCREATESTRUCT) lParam)->lpCreateParams)); - return 0; - - case WM_PAINT: - /* Only paint if our window handle is valid */ - if (hwndScreen == NULL) - break; - - /* BeginPaint gives us an hdc that clips to the invalidated region */ - hdcUpdate = BeginPaint (hwnd, &ps); - -#if 0 - /* NOTE: Doesn't appear to be used - Harold Hunt - 2003/01/15 */ - /* Get the dimensions of the client area */ - GetClientRect (hwnd, &rcClient); -#endif - - /* Get the position and dimensions of the window */ - iBorder = wBorderWidth (pWin); - iX = pWin->drawable.x; - iY = pWin->drawable.y; - iWidth = pWin->drawable.width; - iHeight = pWin->drawable.height; - - /* Try to copy from the shadow buffer */ - if (!BitBlt (hdcUpdate, - 0, 0, - iWidth, iHeight, - s_pScreenPriv->hdcShadow, - iX, iY, - 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), // Default language - (LPTSTR) &lpMsgBuf, - 0, NULL); - - ErrorF ("winTopLevelWindowProc - BitBlt failed: %s\n", - (LPSTR)lpMsgBuf); - LocalFree (lpMsgBuf); - } - - /* EndPaint frees the DC */ - EndPaint (hwndScreen, &ps); - return 0; - - -#if 1 - case WM_MOUSEMOVE: - /* 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); - - /* We can't do anything without privates */ - if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) - break; - - /* Has the mouse pointer crossed screens? */ - if (s_pScreen != miPointerCurrentScreen ()) - miPointerSetNewScreen (s_pScreenInfo->dwScreen, - ptMouse.x - s_pScreenInfo->dwXOffset, - ptMouse.y - s_pScreenInfo->dwYOffset); - - /* Are we tracking yet? */ - if (!s_fTracking) - { - TRACKMOUSEEVENT tme; - - /* Setup data structure */ - ZeroMemory (&tme, sizeof (tme)); - tme.cbSize = sizeof (tme); - tme.dwFlags = TME_LEAVE; - tme.hwndTrack = hwnd; - - /* Call the tracking function */ - if (!(*g_fpTrackMouseEvent) (&tme)) - ErrorF ("winTopLevelWindowProc - _TrackMouseEvent failed\n"); - - /* Flag that we are tracking now */ - s_fTracking = TRUE; - } - - /* Hide or show the Windows mouse cursor */ - if (s_fCursor) - { - /* Hide Windows cursor */ - s_fCursor = FALSE; - ShowCursor (FALSE); - KillTimer (hwnd, s_nIDPollingMouse); - } - - /* Deliver absolute cursor position to X Server */ - miPointerAbsoluteCursor (ptMouse.x - s_pScreenInfo->dwXOffset, - ptMouse.y - s_pScreenInfo->dwYOffset, - g_c32LastInputEventTime = GetTickCount ()); - return 0; - - case WM_NCMOUSEMOVE: - /* - * 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 (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) - break; - - /* Non-client mouse movement, show Windows cursor */ - if (!s_fCursor) - { - s_fCursor = TRUE; - ShowCursor (TRUE); - SetTimer (hwnd, s_nIDPollingMouse, MOUSE_POLLING_INTERVAL, NULL); - } - break; - - case WM_MOUSELEAVE: - /* Mouse has left our client area */ - - /* Flag that we are no longer tracking */ - s_fTracking = FALSE; - - /* Show the mouse cursor, if necessary */ - if (!s_fCursor) - { - s_fCursor = TRUE; - ShowCursor (TRUE); - SetTimer (hwnd, s_nIDPollingMouse, MOUSE_POLLING_INTERVAL, NULL); - } - return 0; - - case WM_LBUTTONDBLCLK: - case WM_LBUTTONDOWN: - if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) - break; - return winMouseButtonsHandle (s_pScreen, ButtonPress, Button1, wParam); - - case WM_LBUTTONUP: - if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) - break; - return winMouseButtonsHandle (s_pScreen, ButtonRelease, Button1, wParam); - - case WM_MBUTTONDBLCLK: - case WM_MBUTTONDOWN: - if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) - break; - return winMouseButtonsHandle (s_pScreen, ButtonPress, Button2, wParam); - - case WM_MBUTTONUP: - if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) - break; - return winMouseButtonsHandle (s_pScreen, ButtonRelease, Button2, wParam); - - case WM_RBUTTONDBLCLK: - case WM_RBUTTONDOWN: - if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) - break; - return winMouseButtonsHandle (s_pScreen, ButtonPress, Button3, wParam); - - case WM_RBUTTONUP: - if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput) - break; - return winMouseButtonsHandle (s_pScreen, ButtonRelease, Button3, wParam); - -#else - - case WM_MOUSEMOVE: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - 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); - - /* Pass the message to the root window */ - SendMessage (hwndScreen, message, wParam, MAKELONG(ptMouse.x, ptMouse.y)); - return 0; - - case WM_NCMOUSEMOVE: - case WM_LBUTTONDBLCLK: - case WM_LBUTTONDOWN: - case WM_LBUTTONUP: - case WM_MBUTTONDBLCLK: - case WM_MBUTTONDOWN: - case WM_MBUTTONUP: - case WM_RBUTTONDBLCLK: - case WM_RBUTTONDOWN: - case WM_RBUTTONUP: - case WM_MOUSELEAVE: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_*BUTTON*\n"); -#endif - - /* Pass the message to the root window */ - SendMessage(hwndScreen, message, wParam, MAKELONG(ptMouse.x, ptMouse.y)); - return 0; -#endif - - case WM_MOUSEWHEEL: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_MOUSEWHEEL\n"); -#endif + strncat (pszClass, "-", 1); + strncat (pszClass, res_name, CLASS_NAME_LENGTH - strlen (pszClass)); + strncat (pszClass, "-", 1); + strncat (pszClass, res_class, CLASS_NAME_LENGTH - strlen (pszClass)); - /* Pass the message to the root window */ - SendMessage(hwndScreen, message, wParam, lParam); - return 0; - - case WM_SYSKEYDOWN: - case WM_SYSKEYUP: - case WM_SYSDEADCHAR: - case WM_KEYDOWN: - case WM_KEYUP: - case WM_DEADCHAR: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_*KEY*\n"); -#endif - - /* Pass the message to the root window */ - SendMessage (hwndScreen, message, wParam, lParam); - return 0; - - case WM_HOTKEY: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_HOTKEY\n"); -#endif - - /* Pass the message to the root window */ - SendMessage (hwndScreen, message, wParam, lParam); - return 0; - - -#if 1 - case WM_ACTIVATE: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_ACTIVATE\n"); -#endif - - /* Pass the message to the root window */ - SendMessage (hwndScreen, message, wParam, lParam); - - /* Bail if inactivating */ - if (LOWORD(wParam) == WA_INACTIVE) - return 0; - - /* Check if the current window is the active window in Windows */ - if (GetActiveWindow () == hwnd) + /* 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 (pWin, &res_role) ) { - /* Tell our Window Manager thread to raise the window */ - wmMsg.msg = WM_WM_RAISE; - winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); + strcat (pszClass, "-"); + strcat (pszClass, res_role); + free (res_role); } - - /* Tell our Window Manager thread to activate the window */ - wmMsg.msg = WM_WM_ACTIVATE; - winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); - - return 0; - - case WM_ACTIVATEAPP: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_ACTIVATEAPP\n"); -#endif - - /* Pass the message to the root window */ - SendMessage (hwndScreen, message, wParam, lParam); - return 0; -#endif - - case WM_CLOSE: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_CLOSE\n"); -#endif - /* Branch on if the window was killed in X already */ - if (pWinPriv->fXKilled) - { - /* Window was killed, go ahead and destroy the window */ - DestroyWindow (hwnd); - } - else - { - /* Tell our Window Manager thread to kill the window */ - wmMsg.msg = WM_WM_KILL; - winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); - } - return 0; - - case WM_DESTROY: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_DESTROY\n"); -#endif - - /* Branch on if the window was killed in X already */ - if (pWinPriv && !pWinPriv->fXKilled) - { - ErrorF ("winTopLevelWindowProc - WM_DESTROY - WM_WM_KILL\n"); - - /* Tell our Window Manager thread to kill the window */ - wmMsg.msg = WM_WM_KILL; - winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); - } - -#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; - - /* 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); -#endif - - /* Notify the X client that its window is moving */ - if (SubStrSend(pWin, pWin->parent)) - SendConfigureNotify (pWin); - - /* Tell X that the window is moving */ - (s_pScreen->MoveWindow) (pWin, - (int)(short) LOWORD(lParam) - wBorderWidth (pWin), - (int)(short) HIWORD(lParam) - wBorderWidth (pWin), - pWin->nextSib, - VTMove); - return 0; - - case WM_SHOWWINDOW: - /* Bail out if the window is being hidden */ - if (!wParam) - return 0; - - /* Tell X to map the window */ - MapWindow (pWin, wClient(pWin)); - - /* */ - if (!pWin->overrideRedirect) - { - DWORD dwExStyle; - DWORD dwStyle; - RECT rcNew; - int iDx, iDy; - - /* Flag that this window needs to be made active when clicked */ - SetProp (hwnd, WIN_NEEDMANAGE_PROP, (HANDLE) 1); - - /* Get the standard and extended window style information */ - dwExStyle = GetWindowLongPtr (hwnd, GWL_EXSTYLE); - dwStyle = GetWindowLongPtr (hwnd, GWL_STYLE); - - /* */ - if (dwExStyle != WS_EX_APPWINDOW) - { - /* Setup a rectangle with the X window position and size */ - SetRect (&rcNew, - pWinPriv->iX, - pWinPriv->iY, - pWinPriv->iX + pWinPriv->iWidth, - pWinPriv->iY + pWinPriv->iHeight); - -#if 0 - ErrorF ("winTopLevelWindowProc - (%d, %d)-(%d, %d)\n", - rcNew.left, rcNew.top, - rcNew.right, rcNew.bottom); -#endif - - /* */ - AdjustWindowRectEx (&rcNew, - WS_POPUP | WS_SIZEBOX | WS_OVERLAPPEDWINDOW, - FALSE, - WS_EX_APPWINDOW); - - /* Calculate position deltas */ - iDx = pWinPriv->iX - rcNew.left; - iDy = pWinPriv->iY - rcNew.top; - - /* Calculate new rectangle */ - rcNew.left += iDx; - rcNew.right += iDx; - rcNew.top += iDy; - rcNew.bottom += iDy; - -#if 0 - ErrorF ("winTopLevelWindowProc - (%d, %d)-(%d, %d)\n", - rcNew.left, rcNew.top, - rcNew.right, rcNew.bottom); -#endif - - /* Set the window extended style flags */ - SetWindowLongPtr (hwnd, GWL_EXSTYLE, WS_EX_APPWINDOW); - - /* Set the window standard style flags */ - SetWindowLongPtr (hwnd, GWL_STYLE, WS_POPUP | WS_SIZEBOX | WS_OVERLAPPEDWINDOW); - - /* Positon the Windows window */ - SetWindowPos (hwnd, HWND_TOP, - rcNew.left, rcNew.top, - rcNew.right - rcNew.left, rcNew.bottom - rcNew.top, - SWP_NOMOVE | SWP_FRAMECHANGED | SWP_SHOWWINDOW | SWP_NOACTIVATE); - - /* Bring the Window window to the foreground */ - SetForegroundWindow (hwnd); - } - } - - /* Setup the Window Manager message */ - wmMsg.msg = WM_WM_MAP; - wmMsg.iWidth = pWinPriv->iWidth; - wmMsg.iHeight = pWinPriv->iHeight; - - /* Tell our Window Manager thread to map the window */ - winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); - - /* Setup the Window Manager message */ - wmMsg.msg = WM_WM_RAISE; - - /* Tell our Window Manager thread to raise the window */ - winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); - return 0; - - case WM_SIZE: - /* see dix/window.c */ - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_SIZE - %d ms\n", GetTickCount ()); -#endif - - switch (wParam) - { - case SIZE_MINIMIZED: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("\tSIZE_MINIMIZED\n"); -#endif - - wmMsg.msg = WM_WM_LOWER; - - /* Tell our Window Manager thread to lower the window */ - winSendMessageToWM (s_pScreenPriv->pWMInfo, &wmMsg); - break; - - case SIZE_RESTORED: - case SIZE_MAXIMIZED: - if (pWinPriv->iWidth == (short) LOWORD(lParam) - && pWinPriv->iHeight == (short) HIWORD(lParam)) - break; - - /* Get the dimensions of the Windows window */ - pWinPriv->iWidth = (short) LOWORD(lParam); - pWinPriv->iHeight = (short) HIWORD(lParam); - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("\t(%d, %d)\n", pWinPriv->iWidth, pWinPriv->iHeight); -#endif - - /* Check if resize events are redirected */ - if ((pWin->eventMask | wOtherEventMasks (pWin)) & ResizeRedirectMask) - { - xEvent eventT; - - /* Setup the X event structure */ - eventT.u.u.type = ResizeRequest; - eventT.u.resizeRequest.window = pWin->drawable.id; - eventT.u.resizeRequest.width = pWinPriv->iWidth; - eventT.u.resizeRequest.height = pWinPriv->iHeight; - - /* */ - if (MaybeDeliverEventsToClient (pWin, &eventT, 1, - ResizeRedirectMask, - wClient(pWin)) == 1) - break; - } - - /* Notify the X client that its window is being resized */ - if (SubStrSend (pWin, pWin->parent)) - SendConfigureNotify (pWin); - - /* Tell the X server that the window is being resized */ - (s_pScreen->ResizeWindow) (pWin, - pWinPriv->iX - wBorderWidth (pWin), - pWinPriv->iY - wBorderWidth (pWin), - pWinPriv->iWidth, - pWinPriv->iHeight, - pWin->nextSib); - - /* Tell X to redraw the exposed portions of the window */ - { - RegionRec temp; - - /* Get the region describing the X window clip list */ - REGION_INIT(s_pScreen, &temp, NullBox, 0); - REGION_COPY(s_pScreen, &temp, &pWin->clipList); - - /* Expose the clipped region */ - (*s_pScreen->WindowExposures) (pWin, &temp, NullRegion); - - /* Free the region */ - REGION_UNINIT(s_pScreen, &temp); - } - break; - -#if 0 - case SIZE_MAXIMIZED: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("\tSIZE_MAXIMIZED\n"); -#endif - - /* Get the dimensions of the window */ - pWinPriv->iWidth = (int)(short) LOWORD(lParam); - pWinPriv->iHeight = (int)(short) HIWORD(lParam); - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("\t(%d, %d)\n", pWinPriv->iWidth, pWinPriv->iHeight); -#endif - - /* */ - if ((pWin->eventMask|wOtherEventMasks(pWin)) & ResizeRedirectMask) - { - xEvent eventT; - - eventT.u.u.type = ResizeRequest; - eventT.u.resizeRequest.window = pWin->drawable.id; - eventT.u.resizeRequest.width = pWinPriv->iWidth; - eventT.u.resizeRequest.height = pWinPriv->iHeight; - if (MaybeDeliverEventsToClient (pWin, &eventT, 1, - ResizeRedirectMask, - wClient(pWin)) == 1); - } - - - (s_pScreen->ResizeWindow) (pWin, - pWinPriv->iX - wBorderWidth (pWin), - pWinPriv->iY - wBorderWidth (pWin), - pWinPriv->iWidth, - pWinPriv->iHeight, - pWin->nextSib); - break; -#endif - - default: - break; - } - return 0; - - case WM_MOUSEACTIVATE: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_MOUSEACTIVATE\n"); -#endif - - /* Check if this window needs to be made active when clicked */ - if (!GetProp (pWinPriv->hWnd, WIN_NEEDMANAGE_PROP)) - { -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_MOUSEACTIVATE - MA_NOACTIVATE\n"); -#endif - - /* */ - return MA_NOACTIVATE; - } - break; - - case WM_TIMER: -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winTopLevelWindowProc - WM_TIMER - %d ms\n", GetTickCount ()); -#endif - - /* Branch on the type of timer event that fired */ - if (wParam == s_nIDPollingMouse) - { - POINT point; - - /* Get the current position of the mouse cursor */ - GetCursorPos (&point); - - /* Deliver absolute cursor position to X Server */ - miPointerAbsoluteCursor (point.x, point.y, - g_c32LastInputEventTime = GetTickCount ()); - } - else - { - ErrorF ("winTopLevelWindowProc - Unknown WM_TIMER\n"); - } - return 0; - - default: - break; + free (res_name); + free (res_class); } - return DefWindowProc (hwnd, message, wParam, lParam); -} - - -/* - * winCreateWindowsWindow - Create a Windows window associated with an X window - */ - -static void -winCreateWindowsWindow (WindowPtr pWin) -{ - int iX, iY; - int iWidth; - int iHeight; - int iBorder; - HWND hWnd; - WNDCLASS wc; - winWindowPriv(pWin); + /* Add incrementing window ID to make unique class name */ + sprintf (pszWindowID, "-%x", s_iWindowID++); + strcat (pszClass, pszWindowID); #if CYGMULTIWINDOW_DEBUG - ErrorF ("winCreateWindowsWindow - pWin: %08x\n", pWin); + ErrorF ("winCreateWindowsWindow - Creating class: %s\n", pszClass); #endif - iBorder = wBorderWidth (pWin); - - iX = pWin->drawable.x; - iY = pWin->drawable.y; - - iWidth = pWin->drawable.width; - iHeight = pWin->drawable.height; - /* Setup our window class */ wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = winTopLevelWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = g_hInstance; - wc.hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN)); + wc.hIcon = hIcon; wc.hCursor = 0; wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); wc.lpszMenuName = NULL; - wc.lpszClassName = WINDOW_CLASS_X; + wc.lpszClassName = pszClass; RegisterClass (&wc); /* Create the window */ - hWnd = CreateWindowExA (WS_EX_TOOLWINDOW, /* Extended styles */ - WINDOW_CLASS_X, /* Class name */ - WINDOW_TITLE_X, /* Window name */ + hWnd = CreateWindowExA (WS_EX_TOOLWINDOW, /* Extended styles */ + pszClass, /* Class name */ + WINDOW_TITLE_X, /* Window name */ WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, - iX, /* Horizontal position */ - iY, /* Vertical position */ - iWidth, /* Right edge */ - iHeight, /* Bottom edge */ - (HWND) NULL, /* No parent or owner window */ - (HMENU) NULL, /* No menu */ - GetModuleHandle (NULL), /* Instance handle */ - pWin); /* ScreenPrivates */ + iX, /* Horizontal position */ + iY, /* Vertical position */ + iWidth, /* Right edge */ + iHeight, /* Bottom edge */ + (HWND) NULL, /* No parent or owner window */ + (HMENU) NULL, /* No menu */ + GetModuleHandle (NULL), /* Instance handle */ + pWin); /* ScreenPrivates */ if (hWnd == NULL) { ErrorF ("winCreateWindowsWindow - CreateWindowExA () failed: %d\n", @@ -1395,7 +553,9 @@ winCreateWindowsWindow (WindowPtr pWin) pWinPriv->hWnd = hWnd; - + /* Cause the "Always On Top" 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 */ @@ -1404,7 +564,8 @@ winCreateWindowsWindow (WindowPtr pWin) /* - * winDestroyWindowsWindow - Destroy a Windows window associated with an X window + * winDestroyWindowsWindow - Destroy a Windows window associated + * with an X window */ static void @@ -1412,21 +573,30 @@ winDestroyWindowsWindow (WindowPtr pWin) { MSG msg; winWindowPriv(pWin); + HICON hiconClass; + HMODULE hInstance; + int iReturn; + char pszClass[512]; #if CYGMULTIWINDOW_DEBUG ErrorF ("winDestroyWindowsWindow\n"); #endif - /* Bail out if the Windows window handle is invalid */ 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); + iReturn = GetClassName (pWinPriv->hWnd, pszClass, 512); + /* Destroy the Windows window */ DestroyWindow (pWinPriv->hWnd); + /* Null our handle to the Window so referencing it will cause an error */ pWinPriv->hWnd = NULL; /* Process all messages on our queue */ @@ -1437,7 +607,30 @@ winDestroyWindowsWindow (WindowPtr pWin) DispatchMessage (&msg); } } - + + /* Only if we were able to get the name */ + if (iReturn) + { +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winDestroyWindowsWindow - Unregistering %s: ", pszClass); +#endif + iReturn = UnregisterClass (pszClass, hInstance); + +#if CYGMULTIWINDOW_DEBUG + 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 + } + } + #if CYGMULTIWINDOW_DEBUG ErrorF ("-winDestroyWindowsWindow\n"); #endif @@ -1445,7 +638,8 @@ winDestroyWindowsWindow (WindowPtr pWin) /* - * winUpdateWindowsWindow - Redisplay/redraw a Windows window associated with an X window + * winUpdateWindowsWindow - Redisplay/redraw a Windows window + * associated with an X window */ static void @@ -1489,19 +683,57 @@ winUpdateWindowsWindow (WindowPtr pWin) } +/* + * winGetWindowID - + */ +XID +winGetWindowID (WindowPtr pWin) +{ + WindowIDPairRec wi = {pWin, 0}; + ClientPtr c = wClient(pWin); + + /* */ + FindClientResourcesByType (c, RT_WINDOW, winFindWindow, &wi); +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winGetWindowID - Window ID: %d\n", wi.id); +#endif + return wi.id; +} +/* + * winMoveXWindow - + */ -typedef struct { - pointer value; - XID id; -} WindowIDPairRec, *WindowIDPairPtr; +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); +} /* @@ -1520,55 +752,111 @@ winFindWindow (pointer value, XID id, pointer cdata) } +#if 0 /* - * winGetWindowID - + * winRestackXWindow - */ -static XID -winGetWindowID (WindowPtr pWin) +static void +winRestackXWindow (WindowPtr pWin, int smode) { - WindowIDPairRec wi = {pWin, 0}; - ClientPtr c = wClient(pWin); - - /* */ - FindClientResourcesByType (c, RT_WINDOW, winFindWindow, &wi); + XID *vlist = malloc(sizeof(unsigned long)); -#if CYGMULTIWINDOW_DEBUG - ErrorF ("winGetWindowID - Window ID: %d\n", wi.id); -#endif + if (vlist == NULL) + { + ErrorF ("winRestackXWindow - malloc () failed\n"); + return; + } - return wi.id; + if (pWin == NULL) + { + ErrorF ("winRestackXWindow - NULL window\n"); + free(vlist); + return; + } + + *((unsigned long*)vlist) = smode; + ConfigureWindow (pWin, CWStackMode, vlist, wClient(pWin)); + + free(vlist); } +#endif /* - * SendConfigureNotify - + * winReorderWindowsMultiWindow - */ -static void -SendConfigureNotify(WindowPtr pWin) +void +winReorderWindowsMultiWindow (ScreenPtr pScreen) { - xEvent event; - winWindowPriv(pWin); + winScreenPriv(pScreen); + HWND hwnd = NULL; + WindowPtr pWin = NULL; + WindowPtr pWinSib = NULL; - event.u.u.type = ConfigureNotify; - event.u.configureNotify.window = pWin->drawable.id; +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winOrderWindowsMultiWindow\n"); +#endif - if (pWin->nextSib) - event.u.configureNotify.aboveSibling = pWin->nextSib->drawable.id; - else - event.u.configureNotify.aboveSibling = None; + pScreenPriv->fRestacking = TRUE; - event.u.configureNotify.x = pWinPriv->iX - wBorderWidth (pWin); - event.u.configureNotify.y = pWinPriv->iY - wBorderWidth (pWin); + if (pScreenPriv->fWindowOrderChanged) + { +#if CYGMULTIWINDOW_DEBUG + ErrorF ("winOrderWindowsMultiWindow - Need to restack\n"); +#endif + hwnd = GetTopWindow (NULL); - event.u.configureNotify.width = pWinPriv->iWidth; - event.u.configureNotify.height = pWinPriv->iHeight; + while (hwnd) + { + if (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; + } + + ((long*)vlist)[0] = winGetWindowID (pWinSib); + ((long*)vlist)[1] = Below; + + ConfigureWindow (pWin, CWSibling | CWStackMode, + vlist, wClient(pWin)); + + free (vlist); + } + } + hwnd = GetNextWindow (hwnd, GW_HWNDNEXT); + } + } - event.u.configureNotify.borderWidth = wBorderWidth (pWin); + pScreenPriv->fRestacking = FALSE; + pScreenPriv->fWindowOrderChanged = FALSE; +} - event.u.configureNotify.override = pWin->overrideRedirect; - /* */ - DeliverEvents (pWin, &event, 1, NullWindow); +/* + * winMinimizeWindow - Minimize in response to WM_CHANGE_STATE + */ + +void +winMinimizeWindow (Window id) +{ + WindowPtr pWin; + winPrivWinPtr pWinPriv; + + pWin = LookupIDByType (id, RT_WINDOW); + + pWinPriv = winGetWindowPriv (pWin); + + ShowWindow (pWinPriv->hWnd, SW_MINIMIZE); } diff --git a/hw/xwin/winmultiwindowwm.c b/hw/xwin/winmultiwindowwm.c index ab4dd27f6..a60d36135 100644 --- a/hw/xwin/winmultiwindowwm.c +++ b/hw/xwin/winmultiwindowwm.c @@ -27,7 +27,7 @@ * * Authors: Kensuke Matsuzaki */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winmultiwindowwm.c,v 1.1 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winmultiwindowwm.c,v 1.3 2003/10/02 13:30:11 eich Exp $ */ /* X headers */ #include <stdio.h> @@ -61,7 +61,6 @@ #define WIN_CONNECT_RETRIES 5 #define WIN_CONNECT_DELAY 5 #define WIN_MSG_QUEUE_FNAME "/dev/windows" -#define WM_WM_X_EVENT 1 #define WIN_JMP_OKAY 0 #define WIN_JMP_ERROR_IO 2 @@ -87,6 +86,7 @@ typedef struct _WMInfo { WMMsgQueueRec wmMsgQueue; Atom atmWmProtos; Atom atmWmDelete; + Atom atmPrivMap; } WMInfoRec, *WMInfoPtr; typedef struct _WMProcArgRec { @@ -95,6 +95,13 @@ typedef struct _WMProcArgRec { pthread_mutex_t *ppmServerStarted; } WMProcArgRec, *WMProcArgPtr; +typedef struct _XMsgProcArgRec { + Display *pDisplay; + DWORD dwScreen; + WMInfoPtr pWMInfo; + pthread_mutex_t *ppmServerStarted; +} XMsgProcArgRec, *XMsgProcArgPtr; + /* * References to external symbols @@ -103,6 +110,7 @@ typedef struct _WMProcArgRec { extern char *display; extern void ErrorF (const char* /*f*/, ...); extern Bool g_fCalledSetLocale; +extern Bool g_fCalledXInitThreads; /* @@ -113,7 +121,7 @@ static void PushMessage (WMMsgQueuePtr pQueue, WMMsgNodePtr pNode); static WMMsgNodePtr -PopMessage (WMMsgQueuePtr pQueue); +PopMessage (WMMsgQueuePtr pQueue, WMInfoPtr pWMInfo); static Bool InitQueue (WMMsgQueuePtr pQueue); @@ -124,15 +132,18 @@ GetWindowName (Display * pDpy, Window iWin, char **ppName); static int SendXMessage (Display *pDisplay, Window iWin, Atom atmType, long nData); +static void +UpdateName (WMInfoPtr pWMInfo, Window iWindow); + static void* winMultiWindowWMProc (void* pArg); -static Bool -FlushXEvents (WMInfoPtr pWMInfo); - static int winMultiWindowWMErrorHandler (Display *pDisp, XErrorEvent *e); +static void * +winMultiWindowXMsgProc (void *pArg); + static void winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg); @@ -146,6 +157,7 @@ winMutliWindowWMIOErrorHandler (Display *pDisplay); static int g_nQueueSize; static jmp_buf g_jmpEntry; +static Bool g_shutdown = FALSE; @@ -212,7 +224,7 @@ PushMessage (WMMsgQueuePtr pQueue, WMMsgNodePtr pNode) } -#if 0 +#if CYGMULTIWINDOW_DEBUG /* * QueueSize - Return the size of the queue */ @@ -233,11 +245,11 @@ QueueSize (WMMsgQueuePtr pQueue) /* - * PopMessage - + * PopMessage - Pop a message from the queue */ static WMMsgNodePtr -PopMessage (WMMsgQueuePtr pQueue) +PopMessage (WMMsgQueuePtr pQueue, WMInfoPtr pWMInfo) { WMMsgNodePtr pNode; @@ -339,7 +351,7 @@ InitQueue (WMMsgQueuePtr pQueue) /* - * GetWindowName - + * GetWindowName - Retrieve the title of an X Window */ static void @@ -360,7 +372,9 @@ GetWindowName (Display *pDisplay, Window iWin, char **ppName) nResult = XGetWMName (pDisplay, iWin, &xtpName); if (!nResult || !xtpName.value || !xtpName.nitems) { +#if CYGMULTIWINDOW_DEBUG ErrorF ("GetWindowName - XGetWMName failed. No name.\n"); +#endif return; } @@ -375,7 +389,7 @@ GetWindowName (Display *pDisplay, Window iWin, char **ppName) } #if CYGMULTIWINDOW_DEBUG - ErrorF ("XA_STRING %s\n", *ppName); + ErrorF ("GetWindowName - XA_STRING %s\n", *ppName); #endif } else @@ -383,7 +397,7 @@ GetWindowName (Display *pDisplay, Window iWin, char **ppName) XmbTextPropertyToTextList (pDisplay, &xtpName, &ppList, &nNum); /* */ - if (nNum && *ppList) + if (nNum && ppList && *ppList) { XFree (xtpName.value); *ppName = strdup (*ppList); @@ -391,13 +405,14 @@ GetWindowName (Display *pDisplay, Window iWin, char **ppName) } #if CYGMULTIWINDOW_DEBUG - ErrorF ("%s %s\n", XGetAtomName (pDisplay, xtpName.encoding), *ppName); + ErrorF ("GetWindowName - %s %s\n", + XGetAtomName (pDisplay, xtpName.encoding), *ppName); #endif } #if CYGMULTIWINDOW_DEBUG - ErrorF ("-GetWindowName\n"); + ErrorF ("GetWindowName - Returning\n"); #endif } @@ -425,6 +440,66 @@ SendXMessage (Display *pDisplay, Window iWin, Atom atmType, long nData) /* + * Updates the name of a HWND according to its X WM_NAME property + */ + +static void +UpdateName (WMInfoPtr pWMInfo, Window iWindow) +{ + char *pszName; + Atom atmType; + int fmtRet; + unsigned long items, remain; + HWND *retHwnd, hWnd; + XWindowAttributes attr; + + hWnd = 0; + + /* 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); + } + } + + /* Some sanity checks */ + if (!hWnd) return; + if (!IsWindow (hWnd)) return; + + /* Set the Windows window name */ + GetWindowName (pWMInfo->pDisplay, iWindow, &pszName); + if (pszName) + { + /* Get the window attributes */ + XGetWindowAttributes (pWMInfo->pDisplay, + iWindow, + &attr); + if (!attr.override_redirect) + { + SetWindowText (hWnd, pszName); + winUpdateIcon (iWindow); + } + + free (pszName); + } +} + + +/* * winMultiWindowWMProc */ @@ -447,7 +522,7 @@ winMultiWindowWMProc (void *pArg) WMMsgNodePtr pNode; /* Pop a message off of our queue */ - pNode = PopMessage (&pWMInfo->wmMsgQueue); + pNode = PopMessage (&pWMInfo->wmMsgQueue, pWMInfo); if (pNode == NULL) { /* Bail if PopMessage returns without a message */ @@ -496,25 +571,17 @@ winMultiWindowWMProc (void *pArg) #if CYGMULTIWINDOW_DEBUG ErrorF ("\tWM_WM_MAP\n"); #endif - { - XWindowAttributes attr; - char *pszName; -#if 0 - XWMHints *pHints; -#endif - - /* Get the window attributes */ - XGetWindowAttributes (pWMInfo->pDisplay, - pNode->msg.iWindow, - &attr); - if (!attr.override_redirect) - { - /* Set the Windows window name */ - GetWindowName(pWMInfo->pDisplay, pNode->msg.iWindow, &pszName); - SetWindowText (pNode->msg.hwndWindow, pszName); - free (pszName); - } - } + /* Put a note as to the HWND associated with this Window */ + XChangeProperty (pWMInfo->pDisplay, + pNode->msg.iWindow, + pWMInfo->atmPrivMap, + pWMInfo->atmPrivMap, + 32, + PropModeReplace, + (unsigned char *) &(pNode->msg.hwndWindow), + 1); + UpdateName (pWMInfo, pNode->msg.iWindow); + winUpdateIcon (pNode->msg.iWindow); break; case WM_WM_UNMAP: @@ -523,7 +590,7 @@ winMultiWindowWMProc (void *pArg) #endif /* Unmap the window */ - XUnmapWindow(pWMInfo->pDisplay, pNode->msg.iWindow); + XUnmapWindow (pWMInfo->pDisplay, pNode->msg.iWindow); break; case WM_WM_KILL: @@ -571,9 +638,17 @@ winMultiWindowWMProc (void *pArg) CurrentTime); break; - case WM_WM_X_EVENT: - /* Process all X events in the Window Manager event queue */ - FlushXEvents (pWMInfo); + case WM_WM_NAME_EVENT: + UpdateName (pWMInfo, pNode->msg.iWindow); + break; + + case WM_WM_HINTS_EVENT: + winUpdateIcon (pNode->msg.iWindow); + break; + + case WM_WM_CHANGE_STATE: + /* Minimize the window in Windows */ + winMinimizeWindow (pNode->msg.iWindow); break; default: @@ -605,71 +680,227 @@ winMultiWindowWMProc (void *pArg) /* - * FlushXEvents - Process any pending X events + * winMultiWindowWMErrorHandler - Our application specific error handler */ -static Bool -FlushXEvents (WMInfoPtr pWMInfo) +static int +winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr) { - XEvent event; - -#if CYGMULTIWINDOW_DEBUG - ErrorF ("FlushXEvents ()\n"); -#endif + char pszErrorMsg[100]; - /* Process all pending events */ - while (XPending (pWMInfo->pDisplay)) + if (pErr->request_code == X_ChangeWindowAttributes + && pErr->error_code == BadAccess) { - /* Get the next event - will not block because one is ready */ - XNextEvent (pWMInfo->pDisplay, &event); - + ErrorF ("winMultiWindowWMErrorHandler - ChangeWindowAttributes " + "BadAccess.\n"); #if 0 - /* Branch on the event type */ - switch (event.type) - { - } + pthread_exit (NULL); #endif + return 0; } + + XGetErrorText (pDisplay, + pErr->error_code, + pszErrorMsg, + sizeof (pszErrorMsg)); + ErrorF ("winMultiWindowWMErrorHandler - ERROR: %s\n", pszErrorMsg); -#if CYGMULTIWINDOW_DEBUG - ErrorF ("-FlushXEvents ()\n"); + if (pErr->error_code == BadWindow + || pErr->error_code == BadMatch + || pErr->error_code == BadDrawable) + { +#if 0 + pthread_exit (NULL); #endif + return 0; + } - return True; + pthread_exit (NULL); + return 0; } /* - * winMultiWindowWMErrorHandler - Our application specific error handler + * */ -static int -winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr) +static void * +winMultiWindowXMsgProc (void *pArg) { - char pszErrorMsg[100]; + winWMMessageRec msg; + XMsgProcArgPtr pProcArg = (XMsgProcArgPtr) pArg; + char pszDisplay[512]; + int iRetries; + XEvent event; + Atom atmWmName; + Atom atmWmHints; + Atom atmWmChange; + int iReturn; + XIconSize *xis; - if (pErr->request_code == X_ChangeWindowAttributes - && pErr->error_code == BadAccess) + ErrorF ("winMultiWindowXMsgProc - Hello\n"); + + /* Check that argument pointer is not invalid */ + if (pProcArg == NULL) { - ErrorF ("ChangeWindowAttributes BadAccess.\n"); + ErrorF ("winMultiWindowXMsgProc - pProcArg is NULL, bailing.\n"); pthread_exit (NULL); } + + ErrorF ("winMultiWindowXMsgProc - 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 ("winMultiWindowXMsgProc - pthread_mutex_lock () failed: %d\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) + { + ErrorF ("winMultiWindowXMsgProc - XInitThreads () failed.\n"); + pthread_exit (NULL); + } + + /* Flag that XInitThreads has been called */ + g_fCalledXInitThreads = TRUE; + + ErrorF ("winMultiWindowXMsgProc - XInitThreads () returned.\n"); + } + + /* Release the server started mutex */ + pthread_mutex_unlock (pProcArg->ppmServerStarted); + + ErrorF ("winMultiWindowXMsgProc - pthread_mutex_unlock () returned.\n"); + + /* Setup the display connection string x */ + snprintf (pszDisplay, + 512, "127.0.0.1:%s.%d", display, (int)pProcArg->dwScreen); + + /* Print the display connection string */ + ErrorF ("winMultiWindowXMsgProc - DISPLAY=%s\n", pszDisplay); - XGetErrorText (pDisplay, - pErr->error_code, - pszErrorMsg, - sizeof (pszErrorMsg)); - ErrorF ("ERROR: %s\n", pszErrorMsg); + iRetries = 0; - if (pErr->error_code==BadWindow - || pErr->error_code==BadMatch - || pErr->error_code==BadDrawable) + /* Open the X display */ + do { + /* Try to open the display */ + pProcArg->pDisplay = XOpenDisplay (pszDisplay); + if (pProcArg->pDisplay == NULL) + { + ErrorF ("winMultiWindowXMsgProc - Could not open display, try: %d, " + "sleeping: %d\n\f", + iRetries + 1, WIN_CONNECT_DELAY); + ++iRetries; + sleep (WIN_CONNECT_DELAY); + continue; + } + else + break; + } + while (pProcArg->pDisplay == NULL && iRetries < WIN_CONNECT_RETRIES); + + /* Make sure that the display opened */ + if (pProcArg->pDisplay == NULL) + { + ErrorF ("winMultiWindowXMsgProcwinInitMultiWindowWM - " + "Failed opening the display, giving up.\n\f"); pthread_exit (NULL); } - pthread_exit (NULL); - return 0; + 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); + + /* Set up the supported icon sizes */ + xis = XAllocIconSize (); + if (xis) + { + xis->min_width = xis->min_height = 16; + xis->max_width = xis->max_height = 48; + xis->width_inc = xis->height_inc = 16; + XSetIconSizes (pProcArg->pDisplay, + RootWindow (pProcArg->pDisplay, pProcArg->dwScreen), + xis, + 1); + XFree (xis); + } + + atmWmName = XInternAtom (pProcArg->pDisplay, + "WM_NAME", + False); + atmWmHints = XInternAtom (pProcArg->pDisplay, + "WM_HINTS", + False); + atmWmChange = XInternAtom (pProcArg->pDisplay, + "WM_CHANGE_STATE", + False); + + /* Loop until we explicitly break out */ + while (1) + { + /* Fetch next event */ + XNextEvent (pProcArg->pDisplay, &event); + + /* Branch on event type */ + if (event.type == CreateNotify) + { + XSelectInput (pProcArg->pDisplay, + event.xcreatewindow.window, + PropertyChangeMask); + } + else if (event.type == PropertyNotify + && event.xproperty.atom == atmWmName) + { + memset (&msg, 0, sizeof (msg)); + + msg.msg = WM_WM_NAME_EVENT; + msg.iWindow = event.xproperty.window; + + /* Other fields ignored */ + winSendMessageToWM (pProcArg->pWMInfo, &msg); + } + else if (event.type == PropertyNotify + && event.xproperty.atom == atmWmHints) + { + memset (&msg, 0, sizeof (msg)); + + msg.msg = WM_WM_HINTS_EVENT; + msg.iWindow = event.xproperty.window; + + /* Other fields ignored */ + winSendMessageToWM (pProcArg->pWMInfo, &msg); + } + else if (event.type == ClientMessage + && event.xclient.message_type == atmWmChange + && event.xclient.data.l[0] == IconicState) + { + ErrorF ("winMultiWindowXMsgProc - WM_CHANGE_STATE - IconicState\n"); + + memset (&msg, 0, sizeof (msg)); + + msg.msg = WM_WM_CHANGE_STATE; + msg.iWindow = event.xclient.window; + + winSendMessageToWM (pProcArg->pWMInfo, &msg); + } + } } @@ -682,12 +913,14 @@ winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr) Bool winInitWM (void **ppWMInfo, pthread_t *ptWMProc, + pthread_t *ptXMsgProc, pthread_mutex_t *ppmServerStarted, int dwScreen) { - WMProcArgPtr pArg = (WMProcArgPtr)malloc (sizeof(WMProcArgRec)); - WMInfoPtr pWMInfo = (WMInfoPtr)malloc (sizeof(WMInfoRec)); - + WMProcArgPtr pArg = (WMProcArgPtr) malloc (sizeof(WMProcArgRec)); + WMInfoPtr pWMInfo = (WMInfoPtr) malloc (sizeof(WMInfoRec)); + XMsgProcArgPtr pXMsgArg = (XMsgProcArgPtr) malloc (sizeof(XMsgProcArgRec)); + /* Bail if the input parameters are bad */ if (pArg == NULL || pWMInfo == NULL) { @@ -714,7 +947,18 @@ winInitWM (void **ppWMInfo, if (pthread_create (ptWMProc, NULL, winMultiWindowWMProc, pArg)) { /* Bail if thread creation failed */ - ErrorF ("winInitWM - pthread_create failed.\n"); + ErrorF ("winInitWM - pthread_create failed for Window Manager.\n"); + return FALSE; + } + + /* Spawn the XNextEvent thread, will send messages to WM */ + pXMsgArg->dwScreen = dwScreen; + pXMsgArg->pWMInfo = pWMInfo; + pXMsgArg->ppmServerStarted = ppmServerStarted; + if (pthread_create (ptXMsgProc, NULL, winMultiWindowXMsgProc, pXMsgArg)) + { + /* Bail if thread creation failed */ + ErrorF ("winInitWM - pthread_create failed on XMSG.\n"); return FALSE; } @@ -788,21 +1032,28 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) /* Flag that we have called setlocale */ g_fCalledSetLocale = TRUE; - /* Release the garbage mutex */ + /* Only call XInitThreads once for the whole process */ + if (!g_fCalledXInitThreads) + { + /* 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"); + } + + /* Release the server started mutex */ pthread_mutex_unlock (pProcArg->ppmServerStarted); ErrorF ("winInitMultiWindowWM - pthread_mutex_unlock () returned.\n"); - /* Allow multiple threads to access Xlib */ - if (XInitThreads () == 0) - { - ErrorF ("winInitMultiWindowWM - XInitThreads () failed.\n"); - pthread_exit (NULL); - } - - ErrorF ("winInitMultiWindowWM - XInitThreads () returned.\n"); - - /* Set jump point for Error exits */ + /* Set jump point for IO Error exits */ iReturn = setjmp (g_jmpEntry); /* Check if we should continue operations */ @@ -814,13 +1065,23 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) 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"); } /* Setup the display connection string x */ - snprintf (pszDisplay, 512, "127.0.0.1:%s.%d", display, pProcArg->dwScreen); + snprintf (pszDisplay, + 512, + "127.0.0.1:%s.%d", + display, + (int) pProcArg->dwScreen); /* Print the display connection string */ ErrorF ("winInitMultiWindowWM - DISPLAY=%s\n", pszDisplay); @@ -866,6 +1127,9 @@ winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) pWMInfo->atmWmDelete = XInternAtom (pWMInfo->pDisplay, "WM_DELETE_WINDOW", False); + pWMInfo->atmPrivMap = XInternAtom (pWMInfo->pDisplay, + WIN_HWND_CACHE, + False); } @@ -905,3 +1169,15 @@ winMutliWindowWMIOErrorHandler (Display *pDisplay) return 0; } + + +/* + * Notify the MWM thread we're exiting and not to reconnect + */ + +void +winDeinitMultiWindowWM () +{ + ErrorF ("winDeinitMultiWindowWM - Noting shutdown in progress\n"); + g_shutdown = TRUE; +} diff --git a/hw/xwin/winnativegdi.c b/hw/xwin/winnativegdi.c index 5fe8b4f38..f7d8a4a1a 100644 --- a/hw/xwin/winnativegdi.c +++ b/hw/xwin/winnativegdi.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winnativegdi.c,v 1.13 2002/10/17 08:18:22 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winnativegdi.c,v 1.15 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" @@ -65,6 +65,17 @@ winCloseScreenNativeGDI (int nIndex, ScreenPtr pScreen) ErrorF ("winCloseScreenNativeGDI - Destroying window\n"); + /* Delete tray icon, if we have one */ + if (!pScreenInfo->fNoTrayIcon) + winDeleteNotifyIcon (pScreenPriv); + + /* Free the exit confirmation dialog box, if it exists */ + if (g_hDlgExit != NULL) + { + DestroyWindow (g_hDlgExit); + g_hDlgExit = NULL; + } + /* Kill our window */ if (pScreenPriv->hwndScreen) { @@ -207,13 +218,28 @@ winAdjustVideoModeNativeGDI (ScreenPtr pScreen) /* Query GDI for current display depth */ dwBPP = GetDeviceCaps (hdc, BITSPIXEL); + pScreenInfo->dwDepth = GetDeviceCaps (hdc, PLANES); + + switch (pScreenInfo->dwDepth) { + case 24: + case 16: + case 15: + case 8: + break; + default: + if (dwBPP == 32) + pScreenInfo->dwDepth = 24; + else + pScreenInfo->dwDepth = dwBPP; + break; + } /* GDI cannot change the screen depth */ if (pScreenInfo->dwBPP == WIN_DEFAULT_BPP) { /* No -depth parameter passed, let the user know the depth being used */ ErrorF ("winAdjustVideoModeNativeGDI - Using Windows display " - "depth of %d bits per pixel\n", dwBPP); + "depth of %d bits per pixel, %d depth\n", dwBPP, pScreenInfo->dwDepth); /* Use GDI's depth */ pScreenInfo->dwBPP = dwBPP; diff --git a/hw/xwin/winpfbdd.c b/hw/xwin/winpfbdd.c index 59d22247e..7cbdb5e53 100644 --- a/hw/xwin/winpfbdd.c +++ b/hw/xwin/winpfbdd.c @@ -30,12 +30,19 @@ * Peter Busch * Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winpfbdd.c,v 1.17 2002/10/17 08:18:22 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winpfbdd.c,v 1.18 2003/07/29 21:25:18 dawes Exp $ */ #include "win.h" /* + * External global variables + */ + +extern const GUID _IID_IDirectDraw2; + + +/* * Create a DirectDraw primary surface */ @@ -259,6 +266,17 @@ winCloseScreenPrimaryDD (int nIndex, ScreenPtr pScreen) pScreenPriv->pdd = NULL; } + /* Delete tray icon, if we have one */ + if (!pScreenInfo->fNoTrayIcon) + winDeleteNotifyIcon (pScreenPriv); + + /* Free the exit confirmation dialog box, if it exists */ + if (g_hDlgExit != NULL) + { + DestroyWindow (g_hDlgExit); + g_hDlgExit = NULL; + } + /* Kill our window */ if (pScreenPriv->hwndScreen) { diff --git a/hw/xwin/winpixmap.c b/hw/xwin/winpixmap.c index 519acedf5..43ade059b 100644 --- a/hw/xwin/winpixmap.c +++ b/hw/xwin/winpixmap.c @@ -28,7 +28,7 @@ * Authors: drewry, september 1986 * Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winpixmap.c,v 1.10 2002/10/17 08:18:24 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winpixmap.c,v 1.11 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" @@ -50,9 +50,11 @@ winCreatePixmapNativeGDI (ScreenPtr pScreen, return NullPixmap; } +#if CYGDEBUG ErrorF ("winCreatePixmap () - w %d h %d d %d bw %d\n", iWidth, iHeight, iDepth, PixmapBytePad (iWidth, iDepth)); +#endif /* Setup pixmap values */ pPixmap->drawable.type = DRAWABLE_PIXMAP; @@ -112,7 +114,9 @@ winDestroyPixmapNativeGDI (PixmapPtr pPixmap) { winPrivPixmapPtr pPixmapPriv = NULL; +#if CYGDEBUG ErrorF ("winDestroyPixmapNativeGDI ()\n"); +#endif /* Bail early if there is not a pixmap to destroy */ if (pPixmap == NULL) @@ -124,8 +128,10 @@ winDestroyPixmapNativeGDI (PixmapPtr pPixmap) /* Get a handle to the pixmap privates */ pPixmapPriv = winGetPixmapPriv (pPixmap); +#if CYGDEBUG ErrorF ("winDestroyPixmapNativeGDI - pPixmapPriv->hBitmap: %08x\n", pPixmapPriv->hBitmap); +#endif /* Decrement reference count, return if nonzero */ --pPixmap->refcnt; diff --git a/hw/xwin/winpolyline.c b/hw/xwin/winpolyline.c index 194ecfe46..948c34428 100644 --- a/hw/xwin/winpolyline.c +++ b/hw/xwin/winpolyline.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winpolyline.c,v 1.3 2001/09/13 08:25:45 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winpolyline.c,v 1.4 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" @@ -39,5 +39,17 @@ winPolyLineNativeGDI (DrawablePtr pDrawable, int npt, DDXPointPtr ppt) { - FatalError ("winPolyLine()\n"); + switch (pGC->lineStyle) + { + case LineSolid: + if (pGC->lineWidth == 0) + return miZeroLine (pDrawable, pGC, mode, npt, ppt); + else + miWideLine (pDrawable, pGC, mode, npt, ppt); + break; + case LineOnOffDash: + case LineDoubleDash: + miWideDash (pDrawable, pGC, mode, npt, ppt); + break; + } } diff --git a/hw/xwin/winscrinit.c b/hw/xwin/winscrinit.c index 41811d253..79e985c6b 100644 --- a/hw/xwin/winscrinit.c +++ b/hw/xwin/winscrinit.c @@ -31,7 +31,7 @@ * Harold L Hunt II * Kensuke Matsuzaki */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winscrinit.c,v 1.26 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winscrinit.c,v 1.28 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" @@ -510,6 +510,11 @@ winFinishScreenInitFB (int index, /* Set the ServerStarted flag to false */ pScreenPriv->fServerStarted = FALSE; + /* Set the WindowOrderChanged flag to false */ + pScreenPriv->fWindowOrderChanged = FALSE; + + pScreenPriv->fRestacking = FALSE; + #if CYGDEBUG || YES if (pScreenInfo->fMultiWindow) ErrorF ("winFinishScreenInitFB - Calling winInitWM.\n"); @@ -519,6 +524,7 @@ winFinishScreenInitFB (int index, if (pScreenInfo->fMultiWindow && !winInitWM (&pScreenPriv->pWMInfo, &pScreenPriv->ptWMProc, + &pScreenPriv->ptXMsgProc, &pScreenPriv->pmServerStarted, pScreenInfo->dwScreen)) { @@ -584,7 +590,7 @@ winFinishScreenInitNativeGDI (int index, int nVisuals = 0, nDepths = 0, nRootDepth = 0; /* Ignore user input (mouse, keyboard) */ - pScreenInfo->fIgnoreInput = TRUE; + pScreenInfo->fIgnoreInput = FALSE; /* Get device contexts for the screen and shadow bitmap */ pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen); @@ -616,7 +622,7 @@ winFinishScreenInitNativeGDI (int index, NULL, /* No framebuffer */ pScreenInfo->dwWidth, pScreenInfo->dwHeight, monitorResolution, monitorResolution, - pScreenInfo->dwWidth, + pScreenInfo->dwStride, nRootDepth, nDepths, pDepths, rootVisual, nVisuals, pVisuals)) { @@ -624,6 +630,8 @@ winFinishScreenInitNativeGDI (int index, return FALSE; } + pScreen->defColormap = FakeClientID(0); + /* * Register our block and wakeup handlers; these procedures * process messages in our Windows message queue; specifically, diff --git a/hw/xwin/winsetsp.c b/hw/xwin/winsetsp.c index 657a7af50..c0340e47b 100644 --- a/hw/xwin/winsetsp.c +++ b/hw/xwin/winsetsp.c @@ -26,8 +26,9 @@ *from the XFree86 Project. * * Authors: Harold L Hunt II + * Alan Hourihane <alanh@fairlite.demon.co.uk> */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winsetsp.c,v 1.7 2001/11/01 12:19:42 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winsetsp.c,v 1.8 2003/08/07 23:47:58 alanh Exp $ */ #include "win.h" @@ -44,22 +45,37 @@ winSetSpansNativeGDI (DrawablePtr pDrawable, winGCPriv(pGC); PixmapPtr pPixmap = NULL; winPrivPixmapPtr pPixmapPriv = NULL; - int iSpan; - int *piWidth = NULL; - DDXPointPtr pPoint = NULL; - char *pSrc = pSrcs; - HDC hdcMem; - BITMAPINFOHEADER *pbmih; - HBITMAP hBitmap = NULL; HBITMAP hbmpOrig = NULL; - DEBUG_FN_NAME("winSetSpans"); - DEBUGVARS; - DEBUGPROC_MSG; + BITMAPINFO bmi; + HRGN hrgn = NULL, combined = NULL; + int nbox; + BoxPtr pbox; + + nbox = REGION_NUM_RECTS (pGC->pCompositeClip); + pbox = REGION_RECTS (pGC->pCompositeClip); + + if (!nbox) return; + + combined = CreateRectRgn (pbox->x1, pbox->y1, pbox->x2, pbox->y2); + nbox--; pbox++; + while (nbox--) + { + hrgn = CreateRectRgn (pbox->x1, pbox->y1, pbox->x2, pbox->y2); + CombineRgn (combined, combined, hrgn, RGN_OR); + DeleteObject (hrgn); + hrgn = NULL; + pbox++; + } /* Branch on the drawable type */ switch (pDrawable->type) { case DRAWABLE_PIXMAP: + + SelectClipRgn (pGCPriv->hdcMem, combined); + DeleteObject (combined); + combined = NULL; + pPixmap = (PixmapPtr) pDrawable; pPixmapPriv = winGetPixmapPriv (pPixmap); @@ -69,264 +85,87 @@ winSetSpansNativeGDI (DrawablePtr pDrawable, FatalError ("winSetSpans - DRAWABLE_PIXMAP - SelectObject () " "failed on pPixmapPriv->hBitmap\n"); - /* Branch on the raster operation type */ - switch (pGC->alu) - { - case GXclear: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXclear\n"); - break; - - case GXand: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXand\n"); - break; - - case GXandReverse: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXandReverse\n"); - break; - - case GXcopy: - ErrorF ("winSetSpans - DRAWABLE_PIXMAP - GXcopy %08x\n", - pDrawable); - - /* Loop through spans */ - for (iSpan = 0; iSpan < iSpans; ++iSpan) - { - piWidth = piWidths + iSpan; - pPoint = pPoints + iSpan; - - /* Blast the bits to the drawable */ - SetDIBits (pGCPriv->hdcMem, - pPixmapPriv->hBitmap, - pPoint->y, 1, - pSrc, - (BITMAPINFO *) pPixmapPriv->pbmih, - 0); - - /* Display some useful information */ - ErrorF ("(%dx%dx%d) (%d,%d) w: %d ps: %08x\n", - pDrawable->width, pDrawable->height, pDrawable->depth, - pPoint->x, pPoint->y, *piWidth, pSrc); - - /* Calculate offset of next bit source */ - pSrc += 4 * ((*piWidth + 31) / 32); - } - - /* - * REMOVE - Visual verification only. - */ - BitBlt (pGCPriv->hdc, - pDrawable->width * 2, pDrawable->height, - pDrawable->width, pDrawable->height, - pGCPriv->hdcMem, - 0, 0, - SRCCOPY); - DEBUG_MSG ("DRAWABLE_PIXMAP - GXcopy"); - break; - - case GXandInverted: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXandInverted\n"); - break; - - case GXnoop: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXnoop\n"); - break; - - case GXxor: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXxor\n"); - break; - - case GXor: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXor\n"); - break; - - case GXnor: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXnor\n"); - break; - - case GXequiv: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXequiv\n"); - break; - - case GXinvert: - ErrorF ("winSetSpans - DRAWABLE_PIXMAP - GXinvert %08x\n", - pDrawable); - - /* Create a temporary DC */ - hdcMem = CreateCompatibleDC (NULL); - - /* Loop through spans */ - for (iSpan = 0; iSpan < iSpans; ++iSpan) - { - piWidth = piWidths + iSpan; - pPoint = pPoints + iSpan; - - /* Create a one-line DIB for the bit data */ - hBitmap = winCreateDIBNativeGDI (*piWidth, 1, pDrawable->depth, - NULL, (BITMAPINFO **) &pbmih); - - /* Select the span line line bitmap into the temporary DC */ - hbmpOrig = SelectObject (hdcMem, hBitmap); - - /* Blast bit data to the one-line DIB */ - SetDIBits (hdcMem, hBitmap, - 0, 1, - pSrc, - (BITMAPINFO *) pbmih, - DIB_RGB_COLORS); - - /* Blit the span line to the drawable */ - BitBlt (pGCPriv->hdcMem, - pPoint->x, pPoint->y, - *piWidth, 1, - hdcMem, - 0, 0, - NOTSRCCOPY); - - /* - * REMOVE - Visual verification only. - */ - BitBlt (pGCPriv->hdc, - pDrawable->width, pDrawable->height + pPoint->y, - *piWidth, 1, - hdcMem, - 0, 0, - SRCCOPY); - - /* Display some useful information */ - ErrorF ("(%dx%dx%d) (%d,%d) w: %d ps: %08x\n", - pDrawable->width, pDrawable->height, pDrawable->depth, - pPoint->x, pPoint->y, *piWidth, pSrc); - - /* Calculate offset of next bit source */ - pSrc += 4 * ((*piWidth + 31) / 32); - - /* Pop the span line bitmap out of the memory DC */ - SelectObject (hdcMem, hbmpOrig); - - /* Free the temporary bitmap */ - DeleteObject (hBitmap); - hBitmap = NULL; - } - - /* - * REMOVE - Visual verification only. - */ - DEBUG_MSG ("DRAWABLE_PIXMAP - GXinvert - Prior to invert"); - BitBlt (pGCPriv->hdc, - pDrawable->width * 2, pDrawable->height, - pDrawable->width, pDrawable->height, - pGCPriv->hdcMem, - 0, 0, - SRCCOPY); - DEBUG_MSG ("DRAWABLE_PIXMAP - GXinvert - Finished invert"); - - /* Release the scratch DC */ - DeleteDC (hdcMem); - break; - - case GXorReverse: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXorReverse\n"); - break; - - case GXcopyInverted: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXcopyInverted\n"); - break; - - case GXorInverted: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXorInverted\n"); - break; - - case GXnand: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXnand\n"); - break; - - case GXset: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - GXset\n"); - break; - - default: - FatalError ("winSetSpans - DRAWABLE_PIXMAP - Unknown ROP\n"); - break; - } + while (iSpans--) + { + ZeroMemory (&bmi, sizeof (BITMAPINFO)); + bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); + bmi.bmiHeader.biWidth = *piWidths; + bmi.bmiHeader.biHeight = 1; + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount = pDrawable->depth; + bmi.bmiHeader.biCompression = BI_RGB; + + /* Setup color table for mono DIBs */ + if (pDrawable->depth == 1) + { + bmi.bmiColors[1].rgbBlue = 255; + bmi.bmiColors[1].rgbGreen = 255; + bmi.bmiColors[1].rgbRed = 255; + } + + StretchDIBits (pGCPriv->hdcMem, + pPoints->x, pPoints->y, + *piWidths, 1, + 0, 0, + *piWidths, 1, + pSrcs, + (BITMAPINFO *) &bmi, + DIB_RGB_COLORS, + g_copyROP[pGC->alu]); + + pSrcs += PixmapBytePad (*piWidths, pDrawable->depth); + pPoints++; + piWidths++; + } + + /* Reset the clip region */ + SelectClipRgn (pGCPriv->hdcMem, NULL); /* Push the drawable pixmap out of the GC HDC */ SelectObject (pGCPriv->hdcMem, hbmpOrig); break; case DRAWABLE_WINDOW: - FatalError ("\nwinSetSpansNativeGDI - DRAWABLE_WINDOW\n\n"); - - /* Branch on the raster operation type */ - switch (pGC->alu) - { - case GXclear: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXclear\n"); - break; - - case GXand: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXand\n"); - break; - - case GXandReverse: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXandReverse\n"); - break; - - case GXcopy: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXcopy\n"); - break; - - case GXandInverted: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXandInverted\n"); - break; - - case GXnoop: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXnoop\n"); - break; - - case GXxor: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXxor\n"); - break; - - case GXor: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXor\n"); - break; - - case GXnor: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXnor\n"); - break; - - case GXequiv: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXequiv\n"); - break; - - case GXinvert: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXinvert\n"); - break; - - case GXorReverse: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXorReverse\n"); - break; - - case GXcopyInverted: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXcopyInverted\n"); - break; - - case GXorInverted: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXorInverted\n"); - break; - - case GXnand: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXnand\n"); - break; - - case GXset: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - GXset\n"); - break; - default: - ErrorF ("winSetSpans () - DRAWABLE_WINDOW - Unknown ROP\n"); - break; - } + SelectClipRgn (pGCPriv->hdc, combined); + DeleteObject (combined); + combined = NULL; + + while (iSpans--) + { + ZeroMemory (&bmi, sizeof (BITMAPINFO)); + bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); + bmi.bmiHeader.biWidth = *piWidths; + bmi.bmiHeader.biHeight = 1; + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount = pDrawable->depth; + bmi.bmiHeader.biCompression = BI_RGB; + + /* Setup color table for mono DIBs */ + if (pDrawable->depth == 1) + { + bmi.bmiColors[1].rgbBlue = 255; + bmi.bmiColors[1].rgbGreen = 255; + bmi.bmiColors[1].rgbRed = 255; + } + + StretchDIBits (pGCPriv->hdc, + pPoints->x, pPoints->y, + *piWidths, 1, + 0, 0, + *piWidths, 1, + pSrcs, + (BITMAPINFO *) &bmi, + DIB_RGB_COLORS, + g_copyROP[pGC->alu]); + + pSrcs += PixmapBytePad (*piWidths, pDrawable->depth); + pPoints++; + piWidths++; + } + + /* Reset the clip region */ + SelectClipRgn (pGCPriv->hdc, NULL); break; case UNDRAWABLE_WINDOW: diff --git a/hw/xwin/winshaddd.c b/hw/xwin/winshaddd.c index 9c14ebf34..a409c27c6 100644 --- a/hw/xwin/winshaddd.c +++ b/hw/xwin/winshaddd.c @@ -30,7 +30,7 @@ * Peter Busch * Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winshaddd.c,v 1.23 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winshaddd.c,v 1.24 2003/07/29 21:25:18 dawes Exp $ */ #include "win.h" @@ -40,7 +40,7 @@ */ #ifdef DEFINE_GUID #undef DEFINE_GUID -#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) GUID_EXT const GUID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} +#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} #endif /* DEFINE_GUID */ @@ -671,6 +671,17 @@ winCloseScreenShadowDD (int nIndex, ScreenPtr pScreen) pScreenPriv->pdd = NULL; } + /* Delete tray icon, if we have one */ + if (!pScreenInfo->fNoTrayIcon) + winDeleteNotifyIcon (pScreenPriv); + + /* Free the exit confirmation dialog box, if it exists */ + if (g_hDlgExit != NULL) + { + DestroyWindow (g_hDlgExit); + g_hDlgExit = NULL; + } + /* Kill our window */ if (pScreenPriv->hwndScreen) { diff --git a/hw/xwin/winshadddnl.c b/hw/xwin/winshadddnl.c index 69396a79b..e902f31b0 100644 --- a/hw/xwin/winshadddnl.c +++ b/hw/xwin/winshadddnl.c @@ -30,7 +30,7 @@ * Peter Busch * Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winshadddnl.c,v 1.24 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winshadddnl.c,v 1.26 2003/10/02 13:30:11 eich Exp $ */ #include "win.h" @@ -40,7 +40,7 @@ */ #ifdef DEFINE_GUID #undef DEFINE_GUID -#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) GUID_EXT const GUID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} +#define DEFINE_GUID(n,l,w1,w2,b1,b2,b3,b4,b5,b6,b7,b8) const GUID n GUID_SECT = {l,w1,w2,{b1,b2,b3,b4,b5,b6,b7,b8}} #endif /* DEFINE_GUID */ /* @@ -51,6 +51,8 @@ DEFINE_GUID( IID_IDirectDraw4, 0x9c59509a,0x39bd,0x11d1,0x8c,0x4a,0x00,0xc0,0x4f,0xd9,0x30,0xc5 ); #endif /* IID_IDirectDraw4 */ +#define FAIL_MSG_MAX_BLT 10 + /* * Create the primary surface and attach the clipper. @@ -514,9 +516,24 @@ winShadowUpdateDDNL (ScreenPtr pScreen, NULL); if (FAILED (ddrval)) { - ErrorF ("winShadowUpdateDDNL - IDirectDrawSurface4_Blt () " - "failed: %08x\n", - ddrval); + static int s_iFailCount = 0; + + if (s_iFailCount < FAIL_MSG_MAX_BLT) + { + ErrorF ("winShadowUpdateDDNL - IDirectDrawSurface4_Blt () " + "failed: %08x\n", + ddrval); + + ++s_iFailCount; + + if (s_iFailCount == FAIL_MSG_MAX_BLT) + { + ErrorF ("winShadowUpdateDDNL - IDirectDrawSurface4_Blt " + "failure message maximum (%d) reached. No " + "more failure messages will be printed.", + FAIL_MSG_MAX_BLT); + } + } } /* Get a pointer to the next box */ @@ -650,6 +667,17 @@ winCloseScreenShadowDDNL (int nIndex, ScreenPtr pScreen) pScreenPriv->pdd = NULL; } + /* Delete tray icon, if we have one */ + if (!pScreenInfo->fNoTrayIcon) + winDeleteNotifyIcon (pScreenPriv); + + /* Free the exit confirmation dialog box, if it exists */ + if (g_hDlgExit != NULL) + { + DestroyWindow (g_hDlgExit); + g_hDlgExit = NULL; + } + /* Kill our window */ if (pScreenPriv->hwndScreen) { diff --git a/hw/xwin/winshadgdi.c b/hw/xwin/winshadgdi.c index d2f72f20d..16b1969d7 100644 --- a/hw/xwin/winshadgdi.c +++ b/hw/xwin/winshadgdi.c @@ -27,7 +27,7 @@ * * Authors: Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winshadgdi.c,v 1.22 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winshadgdi.c,v 1.23 2003/07/29 21:25:18 dawes Exp $ */ #include "win.h" @@ -216,7 +216,7 @@ winRedrawAllProcShadowGDI (HWND hwnd, LPARAM lParam) if (GetClassName (hwnd, strClassName, 100)) { - if(strcmp (WINDOW_CLASS_X, strClassName) == 0) + if (strncmp (WINDOW_CLASS_X, strClassName, strlen (WINDOW_CLASS_X)) == 0) { InvalidateRect (hwnd, NULL, FALSE); UpdateWindow (hwnd); @@ -323,6 +323,17 @@ winAllocateFBShadowGDI (ScreenPtr pScreen) return FALSE; } + /* 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; + } + /* Set screeninfo stride */ pScreenInfo->dwStride = ((dibsection.dsBmih.biSizeImage / dibsection.dsBmih.biHeight) @@ -515,6 +526,17 @@ winCloseScreenShadowGDI (int nIndex, ScreenPtr pScreen) /* Free the screen DC */ ReleaseDC (pScreenPriv->hwndScreen, pScreenPriv->hdcScreen); + /* Delete tray icon, if we have one */ + if (!pScreenInfo->fNoTrayIcon) + winDeleteNotifyIcon (pScreenPriv); + + /* Free the exit confirmation dialog box, if it exists */ + if (g_hDlgExit != NULL) + { + DestroyWindow (g_hDlgExit); + g_hDlgExit = NULL; + } + /* Kill our window */ if (pScreenPriv->hwndScreen) { diff --git a/hw/xwin/winwakeup.c b/hw/xwin/winwakeup.c index 37e062fa6..f311d0dc9 100644 --- a/hw/xwin/winwakeup.c +++ b/hw/xwin/winwakeup.c @@ -30,7 +30,7 @@ * Peter Busch * Harold L Hunt II */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winwakeup.c,v 1.6 2002/10/17 08:18:25 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winwakeup.c,v 1.7 2003/07/29 21:25:18 dawes Exp $ */ #include "win.h" @@ -41,17 +41,23 @@ winWakeupHandler (int nScreen, unsigned long ulResult, pointer pReadmask) { +#if 0 winScreenPriv((ScreenPtr)pWakeupData); +#endif MSG msg; /* Process all messages on our queue */ while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) { - if (g_hDlgDepthChange == 0 || !IsDialogMessage (g_hDlgDepthChange, &msg)) + if ((g_hDlgDepthChange == 0 + || !IsDialogMessage (g_hDlgDepthChange, &msg)) + && (g_hDlgExit == 0 + || !IsDialogMessage (g_hDlgExit, &msg))) { DispatchMessage (&msg); } } + winReorderWindowsMultiWindow ((ScreenPtr)pWakeupData); } diff --git a/hw/xwin/winwindow.c b/hw/xwin/winwindow.c index b2469c30a..6515c8596 100644 --- a/hw/xwin/winwindow.c +++ b/hw/xwin/winwindow.c @@ -28,7 +28,7 @@ * Authors: Harold L Hunt II * Kensuke Matsuzaki */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winwindow.c,v 1.6 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winwindow.c,v 1.9 2003/11/10 18:22:44 tsi Exp $ */ #include "win.h" @@ -41,12 +41,12 @@ winAddRgn (WindowPtr pWindow, pointer data); static void -winUpdateRgn (WindowPtr pWindow); +winUpdateRgnPRootless (WindowPtr pWindow); #ifdef SHAPE static void -winReshape (WindowPtr pWin); +winReshapePRootless (WindowPtr pWin); #endif @@ -91,7 +91,84 @@ winCopyWindowNativeGDI (WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc) { - ErrorF ("winCopyWindowNativeGDI ()\n"); + DDXPointPtr pptSrc; + DDXPointPtr ppt; + RegionPtr prgnDst; + BoxPtr pBox; + int dx, dy; + int i, nbox; + WindowPtr pwinRoot; + BoxPtr pBoxDst, pBoxSrc; + ScreenPtr pScreen = pWin->drawable.pScreen; + winScreenPriv(pScreen); + +#if 0 + ErrorF ("winCopyWindow\n"); +#endif + + /* Get a pointer to the root window */ + pwinRoot = WindowTable[pWin->drawable.pScreen->myNum]; + + /* Create a region for the destination */ + prgnDst = REGION_CREATE(pWin->drawable.pScreen, NULL, 1); + + /* Calculate the shift from the source to the destination */ + dx = ptOldOrg.x - pWin->drawable.x; + dy = ptOldOrg.y - pWin->drawable.y; + + /* Translate the region from the destination to the source? */ + REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy); + REGION_INTERSECT(pWin->drawable.pScreen, prgnDst, &pWin->borderClip, + prgnSrc); + + /* Get a pointer to the first box in the region to be copied */ + pBox = REGION_RECTS(prgnDst); + + /* Get the number of boxes in the region */ + nbox = REGION_NUM_RECTS(prgnDst); + + /* Allocate source points for each box */ + if(!(pptSrc = (DDXPointPtr )ALLOCATE_LOCAL(nbox * sizeof(DDXPointRec)))) + return; + + /* Set an iterator pointer */ + ppt = pptSrc; + + /* Calculate the source point of each box? */ + for (i = nbox; --i >= 0; ppt++, pBox++) + { + ppt->x = pBox->x1 + dx; + ppt->y = pBox->y1 + dy; + } + + /* Setup loop pointers again */ + pBoxDst = REGION_RECTS(prgnDst); + ppt = pptSrc; + +#if 0 + ErrorF ("winCopyWindow - x1\tx2\ty1\ty2\tx\ty\n"); +#endif + + /* BitBlt each source to the destination point */ + for (i = nbox; --i >= 0; pBoxDst++, ppt++) + { +#if 0 + ErrorF ("winCopyWindow - %d\t%d\t%d\t%d\t%d\t%d\n", + pBoxDst->x1, pBoxDst->x2, pBoxDst->y1, pBoxDst->y2, + ppt->x, ppt->y); +#endif + + BitBlt (pScreenPriv->hdcScreen, + pBoxDst->x1, pBoxDst->y1, + pBoxDst->x2 - pBoxDst->x1, pBoxDst->y2 - pBoxDst->y1, + pScreenPriv->hdcScreen, + ppt->x, ppt->y, + SRCCOPY); + } + + /* Cleanup the regions, etc. */ + DEALLOCATE_LOCAL(pptSrc); + REGION_DESTROY(pWin->drawable.pScreen, prgnDst); } @@ -153,7 +230,6 @@ winCreateWindowPRootless (WindowPtr pWin) fResult = winGetScreenPriv(pWin->drawable.pScreen)->CreateWindow(pWin); pWinPriv->hRgn = NULL; - /*winUpdateRgn (pWin);*/ return fResult; } @@ -180,7 +256,7 @@ winDestroyWindowPRootless (WindowPtr pWin) pWinPriv->hRgn = NULL; } - winUpdateRgn (pWin); + winUpdateRgnPRootless (pWin); return fResult; } @@ -200,7 +276,7 @@ winPositionWindowPRootless (WindowPtr pWin, int x, int y) fResult = winGetScreenPriv(pWin->drawable.pScreen)->PositionWindow(pWin, x, y); - winUpdateRgn (pWin); + winUpdateRgnPRootless (pWin); return fResult; } @@ -220,7 +296,7 @@ winChangeWindowAttributesPRootless (WindowPtr pWin, unsigned long mask) fResult = winGetScreenPriv(pWin->drawable.pScreen)->ChangeWindowAttributes(pWin, mask); - winUpdateRgn (pWin); + winUpdateRgnPRootless (pWin); return fResult; } @@ -248,7 +324,7 @@ winUnmapWindowPRootless (WindowPtr pWin) pWinPriv->hRgn = NULL; } - winUpdateRgn (pWin); + winUpdateRgnPRootless (pWin); return fResult; } @@ -269,9 +345,9 @@ winMapWindowPRootless (WindowPtr pWin) fResult = winGetScreenPriv(pWin->drawable.pScreen)->RealizeWindow(pWin); - winReshape (pWin); + winReshapePRootless (pWin); - winUpdateRgn (pWin); + winUpdateRgnPRootless (pWin); return fResult; } @@ -287,8 +363,8 @@ winSetShapePRootless (WindowPtr pWin) winGetScreenPriv(pWin->drawable.pScreen)->SetShape(pWin); - winReshape (pWin); - winUpdateRgn (pWin); + winReshapePRootless (pWin); + winUpdateRgnPRootless (pWin); return; } @@ -366,7 +442,7 @@ winAddRgn (WindowPtr pWin, pointer data) static void -winUpdateRgn (WindowPtr pWin) +winUpdateRgnPRootless (WindowPtr pWin) { HRGN hRgn = CreateRectRgn (0, 0, 0, 0); @@ -378,7 +454,7 @@ winUpdateRgn (WindowPtr pWin) } else { - ErrorF ("winUpdateRgn - CreateRectRgn failed.\n"); + ErrorF ("winUpdateRgnPRootless - CreateRectRgn failed.\n"); } } @@ -386,17 +462,19 @@ winUpdateRgn (WindowPtr pWin) #ifdef SHAPE static void -winReshape (WindowPtr pWin) +winReshapePRootless (WindowPtr pWin) { int nRects; +#if 0 ScreenPtr pScreen = pWin->drawable.pScreen; +#endif RegionRec rrNewShape; BoxPtr pShape, pRects, pEnd; HRGN hRgn, hRgnRect; winWindowPriv(pWin); #if CYGDEBUG - ErrorF ("winReshape ()\n"); + ErrorF ("winReshapePRootless ()\n"); #endif /* Bail if the window is the root window */ @@ -418,7 +496,7 @@ winReshape (WindowPtr pWin) if (!wBoundingShape (pWin)) return; - REGION_INIT(pScreen, &rrNewShape, NullBox, 0); + REGION_NULL(pScreen, &rrNewShape); REGION_COPY(pScreen, &rrNewShape, wBoundingShape(pWin)); REGION_TRANSLATE(pScreen, &rrNewShape, pWin->borderWidth, pWin->borderWidth); @@ -439,13 +517,13 @@ winReshape (WindowPtr pWin) pRects->x2, pRects->y2); if (hRgnRect == NULL) { - ErrorF("winReshape - CreateRectRgn() failed\n"); + ErrorF("winReshapePRootless - CreateRectRgn() failed\n"); } /* Merge the Windows region with the accumulated region */ if (CombineRgn (hRgn, hRgn, hRgnRect, RGN_OR) == ERROR) { - ErrorF("winReshape - CombineRgn() failed\n"); + ErrorF("winReshapePRootless - CombineRgn() failed\n"); } /* Delete the temporary Windows region */ diff --git a/hw/xwin/winwindow.h b/hw/xwin/winwindow.h index d828b4c70..8153b5600 100644 --- a/hw/xwin/winwindow.h +++ b/hw/xwin/winwindow.h @@ -27,7 +27,7 @@ * * Authors: Kensuke Matsuzaki */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winwindow.h,v 1.1 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winwindow.h,v 1.4 2003/10/08 11:13:03 eich Exp $ */ #ifndef _WINWINDOW_H_ @@ -41,20 +41,23 @@ #endif /* Constant strings */ -#define WINDOW_CLASS "cygwin/xfree86 rl" -#define WINDOW_TITLE "Cygwin/XFree86 rl" -#define WIN_SCR_PROP "cyg_screen_prop_rl" +#define WINDOW_CLASS "cygwin/xfree86" +#define WINDOW_TITLE "Cygwin/XFree86 - %s:%d" +#define WINDOW_TITLE_XDMCP "Cygwin/XFree86 - %s" +#define WIN_SCR_PROP "cyg_screen_prop rl" #define WINDOW_CLASS_X "cygwin/xfree86 X rl" -#define WINDOW_TITLE_X "Cygwin/XFree86 X rl" +#define WINDOW_TITLE_X "Cygwin/XFree86 X" #define WIN_WINDOW_PROP "cyg_window_prop_rl" #define WIN_MSG_QUEUE_FNAME "/dev/windows" -#define WIN_LOG_FNAME "/tmp/XWinrl.log" +#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 CYGMULTIWINDOW_DEBUG NO typedef struct _winPrivScreenRec *winPrivScreenPtr; + /* * Window privates */ @@ -70,6 +73,8 @@ typedef struct int iWidth; int iHeight; Bool fXKilled; + Bool fNeedRestore; + POINT ptRestore; } winPrivWinRec, *winPrivWinPtr; typedef struct _winWMMessageRec{ @@ -81,19 +86,22 @@ typedef struct _winWMMessageRec{ int iWidth, iHeight; } winWMMessageRec, *winWMMessagePtr; + /* * winrootlesswm.c */ -#define WM_WM_MOVE (WM_USER + 1) -#define WM_WM_SIZE (WM_USER + 2) -#define WM_WM_RAISE (WM_USER + 3) -#define WM_WM_LOWER (WM_USER + 4) -#define WM_WM_MAP (WM_USER + 5) -#define WM_WM_UNMAP (WM_USER + 6) -#define WM_WM_KILL (WM_USER + 7) -#define WM_WM_ACTIVATE (WM_USER + 8) -#define WMMSG_MSG 10 +#define WM_WM_MOVE (WM_USER + 1) +#define WM_WM_SIZE (WM_USER + 2) +#define WM_WM_RAISE (WM_USER + 3) +#define WM_WM_LOWER (WM_USER + 4) +#define WM_WM_MAP (WM_USER + 5) +#define WM_WM_UNMAP (WM_USER + 6) +#define WM_WM_KILL (WM_USER + 7) +#define WM_WM_ACTIVATE (WM_USER + 8) +#define WM_WM_NAME_EVENT (WM_USER + 9) +#define WM_WM_HINTS_EVENT (WM_USER + 10) +#define WM_WM_CHANGE_STATE (WM_USER + 11) /* @@ -106,13 +114,22 @@ winSendMessageToWM (void *pWMInfo, winWMMessagePtr msg); Bool winInitWM (void **ppWMInfo, pthread_t *ptWMProc, -#if 0 - pthread_cond_t *ppcServerStarted, -#endif + pthread_t *ptXMsgProc, pthread_mutex_t *ppmServerStarted, -#if 0 - Bool *pfServerStarted, -#endif int dwScreen); +void +winDeinitMultiWindowWM (); + +void +winMinimizeWindow (Window id); + + +/* + * winmultiwindowicons.c + */ + +void +winUpdateIcon (Window id); + #endif diff --git a/hw/xwin/winwndproc.c b/hw/xwin/winwndproc.c index 6aa29316d..5b47a212a 100644 --- a/hw/xwin/winwndproc.c +++ b/hw/xwin/winwndproc.c @@ -31,14 +31,18 @@ * Harold L Hunt II * MATSUZAKI Kensuke */ -/* $XFree86: xc/programs/Xserver/hw/xwin/winwndproc.c,v 1.24 2003/02/12 15:01:38 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/hw/xwin/winwndproc.c,v 1.26 2003/10/02 13:30:11 eich Exp $ */ #include "win.h" #include <commctrl.h> +#include "winprefs.h" + +/* + * Global variables + */ + +Bool g_fCursor = TRUE; -BOOL CALLBACK -winChangeDepthDlgProc (HWND hDialog, UINT message, - WPARAM wParam, LPARAM lParam); /* @@ -55,7 +59,6 @@ winWindowProc (HWND hwnd, UINT message, static ScreenPtr s_pScreen = NULL; static HWND s_hwndLastPrivates = NULL; static HINSTANCE s_hInstance; - static Bool s_fCursor = TRUE; static Bool s_fTracking = FALSE; static unsigned long s_ulServerGeneration = 0; int iScanCode; @@ -90,6 +93,10 @@ winWindowProc (HWND hwnd, UINT message, /* Branch on message type */ switch (message) { + case WM_TRAYICON: + return winHandleIconMessage (hwnd, message, wParam, lParam, + s_pScreenPriv); + case WM_CREATE: #if CYGDEBUG ErrorF ("winWindowProc - WM_CREATE\n"); @@ -113,6 +120,23 @@ winWindowProc (HWND hwnd, UINT message, /* Store the mode key states so restore doesn't try to restore them */ winStoreModeKeyStates (s_pScreen); + + /* Setup tray icon */ + if (!s_pScreenInfo->fNoTrayIcon) + { + /* + * NOTE: The WM_CREATE message is processed before CreateWindowEx + * returns, so s_pScreenPriv->hwndScreen is invalid at this point. + * We go ahead and copy our hwnd parameter over top of the screen + * privates hwndScreen so that we have a valid value for + * that member. Otherwise, the tray icon will disappear + * the first time you move the mouse over top of it. + */ + + s_pScreenPriv->hwndScreen = hwnd; + + winInitNotifyIcon (s_pScreenPriv); + } return 0; case WM_DISPLAYCHANGE: @@ -161,7 +185,7 @@ winWindowProc (HWND hwnd, UINT message, * Shadow DirectDraw Non-Locking * Primary DirectDraw * - * TrueColor --> TrueColor depth changs are non-optimal for: + * TrueColor --> TrueColor depth changes are non-optimal for: * Windowed: * Shadow GDI * @@ -189,45 +213,14 @@ winWindowProc (HWND hwnd, UINT message, /* Cannot display the visual until the depth is restored */ ErrorF ("winWindowProc - Disruptive change in depth\n"); - /* Check if the dialog box already exists */ - if (g_hDlgDepthChange != NULL) - { - ErrorF ("winWindowProc - Dialog box already exists\n"); + /* Display Exit dialog */ + winDisplayDepthChangeDialog (s_pScreenPriv); - /* Dialog box already exists, just display it */ - ShowWindow (g_hDlgDepthChange, SW_SHOWDEFAULT); - } - else - { - /* - * Display a notification to the user that the visual - * will not be displayed until the Windows display depth - * is restored to the original value. - */ - g_hDlgDepthChange = CreateDialogParam (s_hInstance, - "DEPTH_CHANGE_BOX", - hwnd, - winChangeDepthDlgProc, - (int) s_pScreenPriv); - - /* Show the dialog box */ - ShowWindow (g_hDlgDepthChange, SW_SHOW); - - ErrorF ("winWindowProc - DialogBox returned: %d\n", - g_hDlgDepthChange); - ErrorF ("winWindowProc - GetLastError: %d\n", GetLastError ()); - - /* Minimize the display window */ - ShowWindow (hwnd, SW_MINIMIZE); - - /* Flag that we have an invalid screen depth */ - s_pScreenPriv->fBadDepth = TRUE; - - /* - * TODO: Redisplay the dialog box if it is not - * currently displayed. - */ - } + /* Flag that we have an invalid screen depth */ + s_pScreenPriv->fBadDepth = TRUE; + + /* Minimize the display window */ + ShowWindow (hwnd, SW_MINIMIZE); } else { @@ -693,17 +686,17 @@ winWindowProc (HWND hwnd, UINT message, } /* Hide or show the Windows mouse cursor */ - if (s_fCursor && (s_pScreenPriv->fActive || s_pScreenInfo->fLessPointer)) + if (g_fCursor && (s_pScreenPriv->fActive || s_pScreenInfo->fLessPointer)) { /* Hide Windows cursor */ - s_fCursor = FALSE; + g_fCursor = FALSE; ShowCursor (FALSE); } - else if (!s_fCursor && !s_pScreenPriv->fActive + else if (!g_fCursor && !s_pScreenPriv->fActive && !s_pScreenInfo->fLessPointer) { /* Show Windows cursor */ - s_fCursor = TRUE; + g_fCursor = TRUE; ShowCursor (TRUE); } @@ -728,9 +721,9 @@ winWindowProc (HWND hwnd, UINT message, break; /* Non-client mouse movement, show Windows cursor */ - if (!s_fCursor) + if (!g_fCursor) { - s_fCursor = TRUE; + g_fCursor = TRUE; ShowCursor (TRUE); } break; @@ -742,9 +735,9 @@ winWindowProc (HWND hwnd, UINT message, s_fTracking = FALSE; /* Show the mouse cursor, if necessary */ - if (!s_fCursor) + if (!g_fCursor) { - s_fCursor = TRUE; + g_fCursor = TRUE; ShowCursor (TRUE); } return 0; @@ -806,6 +799,22 @@ winWindowProc (HWND hwnd, UINT message, /* Clear screen privates flags */ s_pScreenPriv->iE3BCachedPress = 0; break; + + case WIN_POLLING_MOUSE_TIMER_ID: + { + POINT point; + + /* Get the current position of the mouse cursor */ + GetCursorPos (&point); + + /* Map from screen (-X, -Y) to root (0, 0) */ + point.x -= GetSystemMetrics (SM_XVIRTUALSCREEN); + point.y -= GetSystemMetrics (SM_YVIRTUALSCREEN); + + /* Deliver absolute cursor position to X Server */ + miPointerAbsoluteCursor (point.x, point.y, + g_c32LastInputEventTime = GetTickCount()); + } } return 0; @@ -880,7 +889,7 @@ winWindowProc (HWND hwnd, UINT message, && (GetKeyState (VK_MENU) & 0x8000)) || (s_pScreenInfo->fUseUnixKillKey && wParam == VK_BACK && (GetKeyState (VK_MENU) & 0x8000) - && (GetKeyState (VK_CONTROL) & 0x8000))) + && (GetKeyState (VK_CONTROL) & 0x8000))) { /* * Better leave this message here, just in case some unsuspecting @@ -889,8 +898,8 @@ winWindowProc (HWND hwnd, UINT message, */ ErrorF ("winWindowProc - WM_*KEYDOWN - Closekey hit, quitting\n"); - /* Tell our message queue to give up */ - PostMessage (hwnd, WM_CLOSE, 0, 0); + /* Display Exit dialog */ + winDisplayExitDialog (s_pScreenPriv); return 0; } @@ -973,8 +982,6 @@ winWindowProc (HWND hwnd, UINT message, return 0; } - - #if CYGDEBUG ErrorF ("winWindowProc - WM_ACTIVATE\n"); #endif @@ -990,10 +997,10 @@ winWindowProc (HWND hwnd, UINT message, /* Reshow the Windows mouse cursor if we are being deactivated */ if (LOWORD(wParam) == WA_INACTIVE - && !s_fCursor) + && !g_fCursor) { /* Show Windows cursor */ - s_fCursor = TRUE; + g_fCursor = TRUE; ShowCursor (TRUE); } return 0; @@ -1012,10 +1019,10 @@ winWindowProc (HWND hwnd, UINT message, /* Reshow the Windows mouse cursor if we are being deactivated */ if (!s_pScreenPriv->fActive - && !s_fCursor) + && !g_fCursor) { /* Show Windows cursor */ - s_fCursor = TRUE; + g_fCursor = TRUE; ShowCursor (TRUE); } @@ -1023,109 +1030,43 @@ winWindowProc (HWND hwnd, UINT message, (*s_pScreenPriv->pwinActivateApp) (s_pScreen); return 0; - case WM_CLOSE: - /* Tell X that we are giving up */ - GiveUp (0); - return 0; - } - - return DefWindowProc (hwnd, message, wParam, lParam); -} - - -/* - * Process messages for the dialog that is displayed for - * disruptive screen depth changes. - */ - -BOOL CALLBACK -winChangeDepthDlgProc (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 - ErrorF ("winChangeDepthDlgProc\n"); -#endif - - /* Branch on message type */ - switch (message) - { - case WM_INITDIALOG: -#if CYGDEBUG - ErrorF ("winChangeDepthDlgProc - 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; - -#if CYGDEBUG - ErrorF ("winChangeDepthDlgProc - WM_INITDIALG - 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, " - "last bpp: %d\n", - s_pScreenInfo->dwBPP, - s_pScreenPriv->dwLastWindowsBitsPixel); -#endif - return TRUE; - - case WM_DISPLAYCHANGE: -#if CYGDEBUG - ErrorF ("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %d, " - "last bpp: %d, new bpp: %d\n", - s_pScreenInfo->dwBPP, - s_pScreenPriv->dwLastWindowsBitsPixel, - wParam); -#endif - - /* Dismiss the dialog if the display returns to the original depth */ - if (wParam == s_pScreenInfo->dwBPP) - { - ErrorF ("winChangeDelthDlgProc - wParam == s_pScreenInfo->dwBPP\n"); - - /* Depth has been restored, dismiss dialog */ - DestroyWindow (g_hDlgDepthChange); - g_hDlgDepthChange = NULL; - - /* Flag that we have a valid screen depth */ - s_pScreenPriv->fBadDepth = FALSE; - } - return TRUE; - case WM_COMMAND: switch (LOWORD (wParam)) { - case IDOK: - case IDCANCEL: - ErrorF ("winChangeDepthDlgProc - WM_COMMAND - IDOK or IDCANCEL\n"); + case ID_APP_EXIT: + /* Display Exit dialog */ + winDisplayExitDialog (s_pScreenPriv); + return 0; - /* - * User dismissed the dialog, hide it until the - * display mode is restored. - */ - ShowWindow (g_hDlgDepthChange, SW_HIDE); - return TRUE; + case ID_APP_HIDE_ROOT: + ShowWindow (s_pScreenPriv->hwndScreen, SW_HIDE); + s_pScreenPriv->fRootWindowShown = FALSE; + return 0; + + case ID_APP_SHOW_ROOT: + ShowWindow (s_pScreenPriv->hwndScreen, SW_SHOW); + s_pScreenPriv->fRootWindowShown = TRUE; + return 0; + + default: + /* It's probably one of the custom menus... */ + return HandleCustomWM_COMMAND (0, LOWORD (wParam)); + } break; - case WM_CLOSE: - ErrorF ("winChangeDepthDlgProc - WM_CLOSE\n"); + case WM_GIVEUP: + /* Tell X that we are giving up */ + winDeinitClipboard (); + winDeinitMultiWindowWM (); + GiveUp (0); + return 0; - /* - * User dismissed the dialog, hide it until the - * display mode is restored. - */ - ShowWindow (g_hDlgDepthChange, SW_HIDE); - return TRUE; + case WM_CLOSE: + /* Display Exit dialog */ + winDisplayExitDialog (s_pScreenPriv); + return 0; } - return FALSE; + return DefWindowProc (hwnd, message, wParam, lParam); } |