diff options
author | marha <marha@users.sourceforge.net> | 2009-11-17 15:53:57 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2009-11-17 15:53:57 +0000 |
commit | 3fce787ffe938bb3e959ff0b3ec231e54d086c76 (patch) | |
tree | 198f537b43a34301bf781c67193c572f6743f925 /xorg-server/hw/xwin | |
parent | 236c69d6034b152598ce35abaf3559b0eaa89c12 (diff) | |
parent | 578938f1cdd5a06dd6fa28167d575ec980322a5d (diff) | |
download | vcxsrv-3fce787ffe938bb3e959ff0b3ec231e54d086c76.tar.gz vcxsrv-3fce787ffe938bb3e959ff0b3ec231e54d086c76.tar.bz2 vcxsrv-3fce787ffe938bb3e959ff0b3ec231e54d086c76.zip |
svn merge ^/branches/released
Diffstat (limited to 'xorg-server/hw/xwin')
28 files changed, 13238 insertions, 12999 deletions
diff --git a/xorg-server/hw/xwin/InitOutput.c b/xorg-server/hw/xwin/InitOutput.c index acf8bc1ea..616490b94 100644 --- a/xorg-server/hw/xwin/InitOutput.c +++ b/xorg-server/hw/xwin/InitOutput.c @@ -1,1150 +1,1148 @@ -/* - -Copyright 1993, 1998 The Open Group -Copyright (C) Colin Harrison 2005-2008 - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - -*/ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" -#include "winmsg.h" -#include "winconfig.h" -#include "winprefs.h" -#ifdef XWIN_CLIPBOARD -#include "X11/Xlocale.h" -#endif -#ifdef DPMSExtension -#include "dpmsproc.h" -#endif -#ifdef __CYGWIN__ -#include <mntent.h> -#endif -#if defined(WIN32) -#include "xkbsrv.h" -#endif - -#ifdef RELOCATE_PROJECTROOT -#undef Status -#include <shlobj.h> -typedef HRESULT (__stdcall * SHGETFOLDERPATHPROC)( - HWND hwndOwner, - int nFolder, - HANDLE hToken, - DWORD dwFlags, - LPSTR pszPath -); -#endif - - -/* - * References to external symbols - */ - -extern int g_iNumScreens; -extern winScreenInfo g_ScreenInfo[]; -extern int g_iLastScreen; -extern char * g_pszCommandLine; -extern Bool g_fSilentFatalError; - -extern const char * g_pszLogFile; -extern Bool g_fLogFileChanged; -extern int g_iLogVerbose; -Bool g_fLogInited; - -extern Bool g_fXdmcpEnabled; -extern Bool g_fAuthEnabled; -#ifdef HAS_DEVWINDOWS -extern int g_fdMessageQueue; -#endif -extern const char * g_pszQueryHost; -extern HINSTANCE g_hInstance; - -#ifdef XWIN_CLIPBOARD -extern Bool g_fUnicodeClipboard; -extern Bool g_fClipboardLaunched; -extern Bool g_fClipboardStarted; -extern pthread_t g_ptClipboardProc; -extern HWND g_hwndClipboard; -extern Bool g_fClipboard; -#endif - -extern HMODULE g_hmodDirectDraw; -extern FARPROC g_fpDirectDrawCreate; -extern FARPROC g_fpDirectDrawCreateClipper; - -extern HMODULE g_hmodCommonControls; -extern FARPROC g_fpTrackMouseEvent; -extern Bool g_fNoHelpMessageBox; -extern Bool g_fSilentDupError; - - -/* - * Function prototypes - */ - -#ifdef XWIN_CLIPBOARD -static void -winClipboardShutdown (void); -#endif - -#if defined(DDXOSVERRORF) -void -OsVendorVErrorF (const char *pszFormat, va_list va_args); -#endif - -void -winInitializeDefaultScreens (void); - -static Bool -winCheckDisplayNumber (void); - -void -winLogCommandLine (int argc, char *argv[]); - -void -winLogVersionInfo (void); - -Bool -winValidateArgs (void); - -#ifdef RELOCATE_PROJECTROOT -const char * -winGetBaseDir(void); -#endif - -static -void glx_debugging(void); - -/* - * For the depth 24 pixmap we default to 32 bits per pixel, but - * we change this pixmap format later if we detect that the display - * is going to be running at 24 bits per pixel. - * - * FIXME: On second thought, don't DIBs only support 32 bits per pixel? - * DIBs are the underlying bitmap used for DirectDraw surfaces, so it - * seems that all pixmap formats with depth 24 would be 32 bits per pixel. - * Confirm whether depth 24 DIBs can have 24 bits per pixel, then remove/keep - * the bits per pixel adjustment and update this comment to reflect the - * situation. Harold Hunt - 2002/07/02 - */ - -static PixmapFormatRec g_PixmapFormats[] = { - { 1, 1, BITMAP_SCANLINE_PAD }, - { 4, 8, BITMAP_SCANLINE_PAD }, - { 8, 8, BITMAP_SCANLINE_PAD }, - { 15, 16, BITMAP_SCANLINE_PAD }, - { 16, 16, BITMAP_SCANLINE_PAD }, - { 24, 32, BITMAP_SCANLINE_PAD }, -#ifdef RENDER - { 32, 32, BITMAP_SCANLINE_PAD } -#endif -}; - -const int NUMFORMATS = sizeof (g_PixmapFormats) / sizeof (g_PixmapFormats[0]); - -#ifdef XWIN_CLIPBOARD -static void -winClipboardShutdown (void) -{ - /* Close down clipboard resources */ - if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted) - { - /* Synchronously destroy the clipboard window */ - if (g_hwndClipboard != NULL) - { - SendMessage (g_hwndClipboard, WM_DESTROY, 0, 0); - /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */ - } - else - return; - - /* Wait for the clipboard thread to exit */ - pthread_join (g_ptClipboardProc, NULL); - - winDebug ("winClipboardShutdown - Clipboard thread has exited.\n"); - } -} -#endif - - -#if defined(DDXBEFORERESET) -/* - * Called right before KillAllClients when the server is going to reset, - * allows us to shutdown our seperate threads cleanly. - */ - -void -ddxBeforeReset (void) -{ - winDebug ("ddxBeforeReset - Hello\n"); - -#ifdef XWIN_CLIPBOARD - winClipboardShutdown (); -#endif -} -#endif - - -/* See Porting Layer Definition - p. 57 */ -void -ddxGiveUp (void) -{ - int i; - - winDebug ("ddxGiveUp\n"); - - /* Perform per-screen deinitialization */ - for (i = 0; i < g_iNumScreens; ++i) - { - /* Delete the tray icon */ - if (!g_ScreenInfo[i].fNoTrayIcon && g_ScreenInfo[i].pScreen) - winDeleteNotifyIcon (winGetScreenPriv (g_ScreenInfo[i].pScreen)); - } - -#ifdef XWIN_MULTIWINDOW - /* Notify the worker threads we're exiting */ - winDeinitMultiWindowWM (); -#endif - -#ifdef HAS_DEVWINDOWS - /* Close our handle to our message queue */ - if (g_fdMessageQueue != WIN_FD_INVALID) - { - /* Close /dev/windows */ - close (g_fdMessageQueue); - - /* Set the file handle to invalid */ - g_fdMessageQueue = WIN_FD_INVALID; - } -#endif - - if (!g_fLogInited) { - g_pszLogFile = LogInit (g_pszLogFile, NULL); - g_fLogInited = TRUE; - } - LogClose (); - - /* - * At this point we aren't creating any new screens, so - * we are guaranteed to not need the DirectDraw functions. - */ - if (g_hmodDirectDraw != NULL) - { - FreeLibrary (g_hmodDirectDraw); - g_hmodDirectDraw = NULL; - g_fpDirectDrawCreate = NULL; - g_fpDirectDrawCreateClipper = NULL; - } - - /* Unload our TrackMouseEvent funtion pointer */ - if (g_hmodCommonControls != NULL) - { - FreeLibrary (g_hmodCommonControls); - g_hmodCommonControls = NULL; - g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; - } - - /* Free concatenated command line */ - if (g_pszCommandLine) - { - free (g_pszCommandLine); - g_pszCommandLine = NULL; - } - - /* Remove our keyboard hook if it is installed */ - winRemoveKeyboardHookLL (); - - /* Tell Windows that we want to end the app */ - PostQuitMessage (0); -} - - -/* See Porting Layer Definition - p. 57 */ -void -AbortDDX (void) -{ - winDebug ("AbortDDX\n"); - ddxGiveUp (); -} - -#ifdef __CYGWIN__ -/* hasmntopt is currently not implemented for cygwin */ -static const char *winCheckMntOpt(const struct mntent *mnt, const char *opt) -{ - const char *s; - size_t len; - if (mnt == NULL) - return NULL; - if (opt == NULL) - return NULL; - if (mnt->mnt_opts == NULL) - return NULL; - - len = strlen(opt); - s = strstr(mnt->mnt_opts, opt); - if (s == NULL) - return NULL; - if ((s == mnt->mnt_opts || *(s-1) == ',') && (s[len] == 0 || s[len] == ',')) - return (char *)opt; - return NULL; -} - -static void -winCheckMount(void) -{ - FILE *mnt; - struct mntent *ent; - - enum { none = 0, sys_root, user_root, sys_tmp, user_tmp } - level = none, curlevel; - BOOL binary = TRUE; - - mnt = setmntent("/etc/mtab", "r"); - if (mnt == NULL) - { - ErrorF("setmntent failed"); - return; - } - - while ((ent = getmntent(mnt)) != NULL) - { - BOOL system = (strcmp(ent->mnt_type, "system") == 0); - BOOL root = (strcmp(ent->mnt_dir, "/") == 0); - BOOL tmp = (strcmp(ent->mnt_dir, "/tmp") == 0); - - if (system) - { - if (root) - curlevel = sys_root; - else if (tmp) - curlevel = sys_tmp; - else - continue; - } - else - { - if (root) - curlevel = user_root; - else if (tmp) - curlevel = user_tmp; - else - continue; - } - - if (curlevel <= level) - continue; - level = curlevel; - - if (winCheckMntOpt(ent, "binmode") == NULL) - binary = 0; - else - binary = 1; - } - - if (endmntent(mnt) != 1) - { - ErrorF("endmntent failed"); - return; - } - -#ifdef WINDBG - if (!binary) - winDebug("/tmp mounted int textmode\n"); -#endif -} -#else -static void -winCheckMount(void) -{ -} -#endif - -#ifdef RELOCATE_PROJECTROOT -const char * -winGetBaseDir(void) -{ - static BOOL inited = FALSE; - static char buffer[MAX_PATH]; - if (!inited) - { - char *fendptr; - HMODULE module = GetModuleHandle(NULL); - DWORD size = GetModuleFileName(module, buffer, sizeof(buffer)); - if (sizeof(buffer) > 0) - buffer[sizeof(buffer)-1] = 0; - - fendptr = buffer + size; - while (fendptr > buffer) - { - if (*fendptr == '\\' || *fendptr == '/') - { - *fendptr = 0; - break; - } - fendptr--; - } - inited = TRUE; - } - return buffer; -} -#endif - -static void -winFixupPaths (void) -{ - BOOL changed_fontpath = FALSE; - MessageType font_from = X_DEFAULT; -#ifdef RELOCATE_PROJECTROOT - const char *basedir = winGetBaseDir(); - size_t basedirlen = strlen(basedir); -#endif - -#ifdef READ_FONTDIRS - { - /* Open fontpath configuration file */ -#if defined WIN32 && defined __MINGW32__ - static Bool once = False; - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "%s\\font-dirs", basedir); - buffer[sizeof(buffer)-1] = 0; - FILE *fontdirs = fopen(buffer, "rt"); - if (once) fontdirs = NULL; - else once = True; -#else - FILE *fontdirs = fopen(ETCX11DIR "/font-dirs", "rt"); -#endif - if (fontdirs != NULL) - { - char buffer[256]; - int needs_sep = TRUE; - int comment_block = FALSE; - - /* get defautl fontpath */ - char *fontpath = xstrdup(defaultFontPath); - size_t size = strlen(fontpath); - - /* read all lines */ - while (!feof(fontdirs)) - { - size_t blen; - char *hashchar; - char *str; - int has_eol = FALSE; - - /* read one line */ - str = fgets(buffer, sizeof(buffer), fontdirs); - if (str == NULL) /* stop on error or eof */ - break; - - if (strchr(str, '\n') != NULL) - has_eol = TRUE; - - /* check if block is continued comment */ - if (comment_block) - { - /* ignore all input */ - *str = 0; - blen = 0; - if (has_eol) /* check if line ended in this block */ - comment_block = FALSE; - } - else - { - /* find comment character. ignore all trailing input */ - hashchar = strchr(str, '#'); - if (hashchar != NULL) - { - *hashchar = 0; - if (!has_eol) /* mark next block as continued comment */ - comment_block = TRUE; - } - } - - /* strip whitespaces from beginning */ - while (*str == ' ' || *str == '\t') - str++; - - /* get size, strip whitespaces from end */ - blen = strlen(str); - while (blen > 0 && (str[blen-1] == ' ' || - str[blen-1] == '\t' || str[blen-1] == '\n')) - { - str[--blen] = 0; - } - - /* still something left to add? */ - if (blen > 0) - { - size_t newsize = size + blen; - /* reserve one character more for ',' */ - if (needs_sep) - newsize++; - - /* allocate memory */ - if (fontpath == NULL) - fontpath = malloc(newsize+1); - else - fontpath = realloc(fontpath, newsize+1); - - /* add separator */ - if (needs_sep) - { - fontpath[size] = ','; - size++; - needs_sep = FALSE; - } - - /* mark next line as new entry */ - if (has_eol) - needs_sep = TRUE; - - /* add block */ - strncpy(fontpath + size, str, blen); - fontpath[newsize] = 0; - size = newsize; - } - } - - /* cleanup */ - fclose(fontdirs); - defaultFontPath = xstrdup(fontpath); - free(fontpath); - changed_fontpath = TRUE; - font_from = X_CONFIG; - } - } -#endif /* READ_FONTDIRS */ -#ifdef RELOCATE_PROJECTROOT - { - const char *libx11dir = PROJECTROOT "/lib/X11"; - size_t libx11dir_len = strlen(libx11dir); - char *newfp = NULL; - size_t newfp_len = 0; - const char *endptr, *ptr, *oldptr = defaultFontPath; - - endptr = oldptr + strlen(oldptr); - ptr = strchr(oldptr, ','); - if (ptr == NULL) - ptr = endptr; - while (ptr != NULL) - { - size_t oldfp_len = (ptr - oldptr); - size_t newsize = oldfp_len; - char *newpath = malloc(newsize + 1); - strncpy(newpath, oldptr, newsize); - newpath[newsize] = 0; - - - if (strncmp(libx11dir, newpath, libx11dir_len) == 0) - { - char *compose; - newsize = newsize - libx11dir_len + basedirlen; - compose = malloc(newsize + 1); - strcpy(compose, basedir); - strncat(compose, newpath + libx11dir_len, newsize - basedirlen); - compose[newsize] = 0; - free(newpath); - newpath = compose; - } - - oldfp_len = newfp_len; - if (oldfp_len > 0) - newfp_len ++; /* space for separator */ - newfp_len += newsize; - - if (newfp == NULL) - newfp = malloc(newfp_len + 1); - else - newfp = realloc(newfp, newfp_len + 1); - - if (oldfp_len > 0) - { - strcpy(newfp + oldfp_len, ","); - oldfp_len++; - } - strcpy(newfp + oldfp_len, newpath); - - free(newpath); - - if (*ptr == 0) - { - oldptr = ptr; - ptr = NULL; - } else - { - oldptr = ptr + 1; - ptr = strchr(oldptr, ','); - if (ptr == NULL) - ptr = endptr; - } - } - - defaultFontPath = xstrdup(newfp); - free(newfp); - changed_fontpath = TRUE; - } -#endif /* RELOCATE_PROJECTROOT */ - if (changed_fontpath) - winDebug ("FontPath set to \"%s\"\n", defaultFontPath); - -#ifdef RELOCATE_PROJECTROOT - if (getenv("XKEYSYMDB") == NULL) - { - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "XKEYSYMDB=%s\\XKeysymDB", - basedir); - buffer[sizeof(buffer)-1] = 0; - putenv(buffer); - } - if (getenv("XERRORDB") == NULL) - { - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "XERRORDB=%s\\XErrorDB", - basedir); - buffer[sizeof(buffer)-1] = 0; - putenv(buffer); - } - if (getenv("XLOCALEDIR") == NULL) - { - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "XLOCALEDIR=%s\\locale", - basedir); - buffer[sizeof(buffer)-1] = 0; - putenv(buffer); - } - if (getenv("XHOSTPREFIX") == NULL) - { - char buffer[MAX_PATH]; - snprintf(buffer, sizeof(buffer), "XHOSTPREFIX=%s\\X", - basedir); - buffer[sizeof(buffer)-1] = 0; - putenv(buffer); - } - if (getenv("HOME") == NULL) - { - HMODULE shfolder; - SHGETFOLDERPATHPROC shgetfolderpath = NULL; - char buffer[MAX_PATH + 5]; - strncpy(buffer, "HOME=", 5); - - /* Try to load SHGetFolderPath from shfolder.dll and shell32.dll */ - - shfolder = LoadLibrary("shfolder.dll"); - /* fallback to shell32.dll */ - if (shfolder == NULL) - shfolder = LoadLibrary("shell32.dll"); - - /* resolve SHGetFolderPath */ - if (shfolder != NULL) - shgetfolderpath = (SHGETFOLDERPATHPROC)GetProcAddress(shfolder, "SHGetFolderPathA"); - - /* query appdata directory */ - if (shgetfolderpath && - shgetfolderpath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, - buffer + 5) == 0) - { - putenv(buffer); - } else - { - ErrorF ("Can not determine HOME directory\n"); - } - if (shfolder != NULL) - FreeLibrary(shfolder); - } - if (!g_fLogFileChanged) { - static char buffer[MAX_PATH]; - DWORD size = GetTempPath(sizeof(buffer), buffer); - if (size && size < sizeof(buffer)) - { - snprintf(buffer + size, sizeof(buffer) - size, - "VCXSrv.%s.log", display); - buffer[sizeof(buffer)-1] = 0; - g_pszLogFile = buffer; - GetLongPathName(buffer, buffer, MAX_PATH); - winDebug ("Logfile set to \"%s\"\n", g_pszLogFile); - } - } - { - static char xkbbasedir[MAX_PATH]; - - snprintf(xkbbasedir, sizeof(xkbbasedir), "%s\\xkbdata", basedir); - if (sizeof(xkbbasedir) > 0) - xkbbasedir[sizeof(xkbbasedir)-1] = 0; - XkbBaseDirectory = xkbbasedir; - XkbBinDirectory = basedir; - } -#endif /* RELOCATE_PROJECTROOT */ -} - -void -OsVendorInit (void) -{ - /* Re-initialize global variables on server reset */ - winInitializeGlobals (); - - winFixupPaths(); - -#ifdef DDXOSVERRORF - if (!OsVendorVErrorFProc) - OsVendorVErrorFProc = OsVendorVErrorF; -#endif - - if (!g_fLogInited) { - /* keep this order. If LogInit fails it calls Abort which then calls - * ddxGiveUp where LogInit is called again and creates an infinite - * recursion. If we set g_fLogInited to TRUE before the init we - * avoid the second call - */ - g_fLogInited = TRUE; - g_pszLogFile = LogInit (g_pszLogFile, NULL); - } - LogSetParameter (XLOG_FLUSH, 1); - LogSetParameter (XLOG_VERBOSITY, g_iLogVerbose); - LogSetParameter (XLOG_FILE_VERBOSITY, g_iLogVerbose); - - /* Log the version information */ - if (serverGeneration == 1) - winLogVersionInfo (); - - winCheckMount(); - - /* Add a default screen if no screens were specified */ - if (g_iNumScreens == 0) - { - winDebug ("OsVendorInit - Creating bogus screen 0\n"); - - /* - * We need to initialize default screens if no arguments - * were processed. Otherwise, the default screens would - * already have been initialized by ddxProcessArgument (). - */ - winInitializeDefaultScreens (); - - /* - * Add a screen 0 using the defaults set by - * winInitializeDefaultScreens () and any additional parameters - * processed by ddxProcessArgument (). - */ - g_iNumScreens = 1; - g_iLastScreen = 0; - - /* We have to flag this as an explicit screen, even though it isn't */ - g_ScreenInfo[0].fExplicitScreen = TRUE; - } -} - - -static void -winUseMsg (void) -{ - ErrorF ("-depth bits_per_pixel\n" - "\tSpecify an optional bitdepth to use in fullscreen mode\n" - "\twith a DirectDraw engine.\n"); - - ErrorF ("-emulate3buttons [timeout]\n" - "\tEmulate 3 button mouse with an optional timeout in\n" - "\tmilliseconds.\n"); - - ErrorF ("-engine engine_type_id\n" - "\tOverride the server's automatically selected engine type:\n" - "\t\t1 - Shadow GDI\n" - "\t\t2 - Shadow DirectDraw\n" - "\t\t4 - Shadow DirectDraw4 Non-Locking\n" -#ifdef XWIN_NATIVEGDI - "\t\t16 - Native GDI - experimental\n" -#endif - ); - - ErrorF ("-fullscreen\n" - "\tRun the server in fullscreen mode.\n"); - - ErrorF ("-refresh rate_in_Hz\n" - "\tSpecify an optional refresh rate to use in fullscreen mode\n" - "\twith a DirectDraw engine.\n"); - - ErrorF ("-screen scr_num [width height [x y] | [[WxH[+X+Y]][@m]] ]\n" - "\tEnable screen scr_num and optionally specify a width and\n" - "\theight and initial position for that screen. Additionally\n" - "\ta monitor number can be specified to start the server on,\n" - "\tat which point, all coordinates become relative to that\n" - "\tmonitor (Not for Windows NT4 and 95). Examples:\n" - "\t -screen 0 800x600+100+100@2 ; 2nd monitor offset 100,100 size 800x600\n" - "\t -screen 0 1024x768@3 ; 3rd monitor size 1024x768\n" - "\t -screen 0 @1 ; on 1st monitor using its full resolution (the default)\n"); - - ErrorF ("-lesspointer\n" - "\tHide the windows mouse pointer when it is over an inactive\n" - "\t" PROJECT_NAME " window. This prevents ghost cursors appearing where\n" - "\tthe Windows cursor is drawn overtop of the X cursor\n"); - - ErrorF ("-nodecoration\n" - "\tDo not draw a window border, title bar, etc. Windowed\n" - "\tmode only.\n"); - -#ifdef XWIN_MULTIWINDOWEXTWM - ErrorF ("-mwextwm\n" - "\tRun the server in multi-window external window manager mode.\n"); - - ErrorF ("-internalwm\n" - "\tRun the internal window manager.\n"); -#endif - - ErrorF ("-rootless\n" - "\tRun the server in rootless mode.\n"); - -#ifdef XWIN_MULTIWINDOW - ErrorF ("-multiwindow\n" - "\tRun the server in multi-window mode.\n"); -#endif - - ErrorF ("-multiplemonitors\n" - "\tEXPERIMENTAL: Use the entire virtual screen if multiple\n" - "\tmonitors are present.\n"); - -#ifdef XWIN_CLIPBOARD - ErrorF ("-clipboard\n" - "\tRun the clipboard integration module.\n" - "\tDo not use at the same time as 'xwinclip'.\n"); - - ErrorF ("-nounicodeclipboard\n" - "\tDo not use Unicode clipboard even if NT-based platform.\n"); -#endif - - ErrorF ("-scrollbars\n" - "\tIn windowed mode, allow screens bigger than the Windows desktop.\n" - "\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" - "\tupdated region. Currently supported only by `-engine 1'.\n"); - -#ifdef XWIN_EMULATEPSEUDO - ErrorF ("-emulatepseudo\n" - "\tCreate a depth 8 PseudoColor visual when running in\n" - "\tdepths 15, 16, 24, or 32, collectively known as TrueColor\n" - "\tdepths. The PseudoColor visual does not have correct colors,\n" - "\tand it may crash, but it at least allows you to run your\n" - "\tapplication in TrueColor modes.\n"); -#endif - - ErrorF ("-[no]unixkill\n" - "\tCtrl+Alt+Backspace exits the X Server.\n"); - - ErrorF ("-[no]winkill\n" - "\tAlt+F4 exits the X Server.\n"); - -#ifdef XWIN_XF86CONFIG - ErrorF ("-config\n" - "\tSpecify a configuration file.\n"); - - ErrorF ("-keyboard\n" - "\tSpecify a keyboard device from the configuration file.\n"); -#endif - - ErrorF ("-xkbrules XKBRules\n" - "\tEquivalent to XKBRules in XF86Config files.\n"); - - ErrorF ("-xkbmodel XKBModel\n" - "\tEquivalent to XKBModel in XF86Config files.\n"); - - ErrorF ("-xkblayout XKBLayout\n" - "\tEquivalent to XKBLayout in XF86Config files.\n" - "\tFor example: -xkblayout de\n"); - - ErrorF ("-xkbvariant XKBVariant\n" - "\tEquivalent to XKBVariant in XF86Config files.\n" - "\tFor example: -xkbvariant nodeadkeys\n"); - - ErrorF ("-xkboptions XKBOptions\n" - "\tEquivalent to XKBOptions in XF86Config files.\n"); - - ErrorF ("-logfile filename\n" - "\tWrite logmessages to <filename>.\n"); - - ErrorF ("-logverbose verbosity\n" - "\tSet the verbosity of logmessages. [NOTE: Only a few messages\n" - "\trespect the settings yet]\n" - "\t\t0 - only print fatal error.\n" - "\t\t1 - print additional configuration information.\n" - "\t\t2 - print additional runtime information [default].\n" - "\t\t3 - print debugging and tracing information.\n"); - - ErrorF ("-[no]keyhook\n" - "\tGrab special windows key combinations like Alt-Tab or the Menu " - "key.\n These keys are discarded by default.\n"); - - ErrorF ("-swcursor\n" - "\tDisable the usage of the windows cursor and use the X11 software " - "cursor instead\n"); -} - -/* See Porting Layer Definition - p. 57 */ -void -ddxUseMsg(void) -{ - /* Set a flag so that FatalError won't give duplicate warning message */ - g_fSilentFatalError = TRUE; - - winUseMsg(); - - /* Log file will not be opened for UseMsg unless we open it now */ - if (!g_fLogInited) { - g_pszLogFile = LogInit (g_pszLogFile, NULL); - g_fLogInited = TRUE; - } - LogClose (); - - /* Notify user where UseMsg text can be found.*/ - if (!g_fNoHelpMessageBox) - winMessageBoxF ("The " PROJECT_NAME " help text has been printed to " - "%s.\n" - "Please open %s to read the help text.\n", - MB_ICONINFORMATION, g_pszLogFile, g_pszLogFile); -} - -/* See Porting Layer Definition - p. 20 */ -/* - * Do any global initialization, then initialize each screen. - * - * NOTE: We use ddxProcessArgument, so we don't need to touch argc and argv - */ - -void -InitOutput (ScreenInfo *screenInfo, int argc, char *argv[]) -{ - int i; - - /* Log the command line */ - winLogCommandLine (argc, argv); - - winDebug ("InitOutput\n"); - - /* Validate command-line arguments */ - if (serverGeneration == 1 && !winValidateArgs ()) - { - FatalError ("InitOutput - Invalid command-line arguments found. " - "Exiting.\n"); - } - - /* Check for duplicate invocation on same display number.*/ - if (serverGeneration == 1 && !winCheckDisplayNumber ()) - { - if (g_fSilentDupError) - g_fSilentFatalError = TRUE; - FatalError ("InitOutput - Duplicate invocation on display " - "number: %s. Exiting.\n", display); - } - -#ifdef XWIN_XF86CONFIG - /* Try to read the xorg.conf-style configuration file */ - if (!winReadConfigfile ()) - ErrorF ("InitOutput - Error reading config file\n"); -#else - winConfigFiles (); -#endif - - /* Load preferences from XWinrc file */ - LoadPreferences(); - - /* Setup global screen info parameters */ - screenInfo->imageByteOrder = IMAGE_BYTE_ORDER; - screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD; - screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT; - screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER; - screenInfo->numPixmapFormats = NUMFORMATS; - - /* Describe how we want common pixmap formats padded */ - for (i = 0; i < NUMFORMATS; i++) - { - screenInfo->formats[i] = g_PixmapFormats[i]; - } - - /* Load pointers to DirectDraw functions */ - winGetDDProcAddresses (); - - /* Detect supported engines */ - winDetectSupportedEngines (); - - /* Load common controls library */ - g_hmodCommonControls = LoadLibraryEx ("comctl32.dll", NULL, 0); - - /* Load TrackMouseEvent function pointer */ - g_fpTrackMouseEvent = GetProcAddress (g_hmodCommonControls, - "_TrackMouseEvent"); - if (g_fpTrackMouseEvent == NULL) - { - ErrorF ("InitOutput - Could not get pointer to function\n" - "\t_TrackMouseEvent in comctl32.dll. Try installing\n" - "\tInternet Explorer 3.0 or greater if you have not\n" - "\talready.\n"); - - /* Free the library since we won't need it */ - FreeLibrary (g_hmodCommonControls); - g_hmodCommonControls = NULL; - - /* Set function pointer to point to no operation function */ - g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; - } - - /* Store the instance handle */ - g_hInstance = GetModuleHandle (NULL); - - /* Initialize each screen */ - for (i = 0; i < g_iNumScreens; ++i) - { - /* Initialize the screen */ - if (-1 == AddScreen (winScreenInit, argc, argv)) - { - FatalError ("InitOutput - Couldn't add screen %d", i); - } - } - -#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) - -#if defined(XCSECURITY) - /* Generate a cookie used by internal clients for authorization */ - if (g_fXdmcpEnabled || g_fAuthEnabled) - winGenerateAuthorization (); -#endif - - /* Perform some one time initialization */ - if (1 == serverGeneration) - { - /* - * setlocale applies to all threads in the current process. - * Apply locale specified in LANG environment variable. - */ - setlocale (LC_ALL, ""); - - glx_debugging(); - } -#endif - - winDebug ("InitOutput - Returning.\n"); -} - - -/* - * winCheckDisplayNumber - Check if another instance of Cygwin/X is - * already running on the same display number. If no one exists, - * make a mutex to prevent new instances from running on the same display. - * - * return FALSE if the display number is already used. - */ - -static Bool -winCheckDisplayNumber (void) -{ - int nDisp; - HANDLE mutex; - char name[MAX_PATH]; - char * pszPrefix = '\0'; - OSVERSIONINFO osvi = {0}; - - /* Check display range */ - nDisp = atoi (display); - if (nDisp < 0 || nDisp > 59535) - { - ErrorF ("winCheckDisplayNumber - Bad display number: %d\n", nDisp); - return FALSE; - } - - /* Set first character of mutex name to null */ - name[0] = '\0'; - - /* Get operating system version information */ - osvi.dwOSVersionInfoSize = sizeof (osvi); - GetVersionEx (&osvi); - - /* Want a mutex shared among all terminals on NT > 4.0 */ - if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT - && osvi.dwMajorVersion >= 5) - { - pszPrefix = "Global\\"; - } - - /* Setup Cygwin/X specific part of name */ - snprintf (name, sizeof(name), "%sCYGWINX_DISPLAY:%d", pszPrefix, nDisp); - - /* Windows automatically releases the mutex when this process exits */ - mutex = CreateMutex (NULL, FALSE, name); - if (!mutex) - { - LPVOID lpMsgBuf; - - /* Display a fancy error message */ - FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - GetLastError (), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR) &lpMsgBuf, - 0, NULL); - ErrorF ("winCheckDisplayNumber - CreateMutex failed: %s\n", - (LPSTR)lpMsgBuf); - LocalFree (lpMsgBuf); - - return FALSE; - } - if (GetLastError () == ERROR_ALREADY_EXISTS) - { - ErrorF ("winCheckDisplayNumber - " - "VCXsrv, Xming or Cygwin/X is already running on display %d\n", - nDisp); - return FALSE; - } - - return TRUE; -} - -/* GLX debugging helpers */ -#include <../glx/glapi.h> - -static -void warn_func(void * p1, const char *format, ...) { - va_list v; - va_start(v, format); - vfprintf(stderr, format, v); - va_end(v); - fprintf(stderr,"\n"); -} - -static -void glx_debugging(void) -{ - _glapi_set_warning_func(warn_func); - _glapi_noop_enable_warnings(TRUE); -} +/*
+
+Copyright 1993, 1998 The Open Group
+Copyright (C) Colin Harrison 2005-2008
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#include "winmsg.h"
+#include "winconfig.h"
+#include "winprefs.h"
+#ifdef XWIN_CLIPBOARD
+#include "X11/Xlocale.h"
+#endif
+#ifdef DPMSExtension
+#include "dpmsproc.h"
+#endif
+#ifdef __CYGWIN__
+#include <mntent.h>
+#endif
+#if defined(WIN32)
+#include "xkbsrv.h"
+#endif
+
+#ifdef RELOCATE_PROJECTROOT
+#undef Status
+#include <shlobj.h>
+typedef HRESULT (__stdcall * SHGETFOLDERPATHPROC)(
+ HWND hwndOwner,
+ int nFolder,
+ HANDLE hToken,
+ DWORD dwFlags,
+ LPSTR pszPath
+);
+#endif
+
+
+/*
+ * References to external symbols
+ */
+
+extern int g_iNumScreens;
+extern winScreenInfo g_ScreenInfo[];
+extern int g_iLastScreen;
+extern char * g_pszCommandLine;
+extern Bool g_fSilentFatalError;
+
+extern const char * g_pszLogFile;
+extern Bool g_fLogFileChanged;
+extern int g_iLogVerbose;
+Bool g_fLogInited;
+
+extern Bool g_fXdmcpEnabled;
+extern Bool g_fAuthEnabled;
+#ifdef HAS_DEVWINDOWS
+extern int g_fdMessageQueue;
+#endif
+extern const char * g_pszQueryHost;
+extern HINSTANCE g_hInstance;
+
+#ifdef XWIN_CLIPBOARD
+extern Bool g_fUnicodeClipboard;
+extern Bool g_fClipboardLaunched;
+extern Bool g_fClipboardStarted;
+extern pthread_t g_ptClipboardProc;
+extern HWND g_hwndClipboard;
+extern Bool g_fClipboard;
+#endif
+
+extern HMODULE g_hmodDirectDraw;
+extern FARPROC g_fpDirectDrawCreate;
+extern FARPROC g_fpDirectDrawCreateClipper;
+
+extern HMODULE g_hmodCommonControls;
+extern FARPROC g_fpTrackMouseEvent;
+extern Bool g_fNoHelpMessageBox;
+extern Bool g_fSilentDupError;
+
+
+/*
+ * Function prototypes
+ */
+
+#ifdef XWIN_CLIPBOARD
+static void
+winClipboardShutdown (void);
+#endif
+
+#if defined(DDXOSVERRORF)
+void
+OsVendorVErrorF (const char *pszFormat, va_list va_args);
+#endif
+
+void
+winInitializeDefaultScreens (void);
+
+static Bool
+winCheckDisplayNumber (void);
+
+void
+winLogCommandLine (int argc, char *argv[]);
+
+void
+winLogVersionInfo (void);
+
+Bool
+winValidateArgs (void);
+
+#ifdef RELOCATE_PROJECTROOT
+const char *
+winGetBaseDir(void);
+#endif
+
+static
+void glx_debugging(void);
+
+/*
+ * For the depth 24 pixmap we default to 32 bits per pixel, but
+ * we change this pixmap format later if we detect that the display
+ * is going to be running at 24 bits per pixel.
+ *
+ * FIXME: On second thought, don't DIBs only support 32 bits per pixel?
+ * DIBs are the underlying bitmap used for DirectDraw surfaces, so it
+ * seems that all pixmap formats with depth 24 would be 32 bits per pixel.
+ * Confirm whether depth 24 DIBs can have 24 bits per pixel, then remove/keep
+ * the bits per pixel adjustment and update this comment to reflect the
+ * situation. Harold Hunt - 2002/07/02
+ */
+
+static PixmapFormatRec g_PixmapFormats[] = {
+ { 1, 1, BITMAP_SCANLINE_PAD },
+ { 4, 8, BITMAP_SCANLINE_PAD },
+ { 8, 8, BITMAP_SCANLINE_PAD },
+ { 15, 16, BITMAP_SCANLINE_PAD },
+ { 16, 16, BITMAP_SCANLINE_PAD },
+ { 24, 32, BITMAP_SCANLINE_PAD },
+#ifdef RENDER
+ { 32, 32, BITMAP_SCANLINE_PAD }
+#endif
+};
+
+const int NUMFORMATS = sizeof (g_PixmapFormats) / sizeof (g_PixmapFormats[0]);
+
+#ifdef XWIN_CLIPBOARD
+static void
+winClipboardShutdown (void)
+{
+ /* Close down clipboard resources */
+ if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted)
+ {
+ /* Synchronously destroy the clipboard window */
+ if (g_hwndClipboard != NULL)
+ {
+ SendMessage (g_hwndClipboard, WM_DESTROY, 0, 0);
+ /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */
+ }
+ else
+ return;
+
+ /* Wait for the clipboard thread to exit */
+ pthread_join (g_ptClipboardProc, NULL);
+
+ winDebug ("winClipboardShutdown - Clipboard thread has exited.\n");
+ }
+}
+#endif
+
+
+#if defined(DDXBEFORERESET)
+/*
+ * Called right before KillAllClients when the server is going to reset,
+ * allows us to shutdown our seperate threads cleanly.
+ */
+
+void
+ddxBeforeReset (void)
+{
+ winDebug ("ddxBeforeReset - Hello\n");
+
+#ifdef XWIN_CLIPBOARD
+ winClipboardShutdown ();
+#endif
+}
+#endif
+
+
+/* See Porting Layer Definition - p. 57 */
+void
+ddxGiveUp (void)
+{
+ int i;
+
+ winDebug ("ddxGiveUp\n");
+
+ /* Perform per-screen deinitialization */
+ for (i = 0; i < g_iNumScreens; ++i)
+ {
+ /* Delete the tray icon */
+ if (!g_ScreenInfo[i].fNoTrayIcon && g_ScreenInfo[i].pScreen)
+ winDeleteNotifyIcon (winGetScreenPriv (g_ScreenInfo[i].pScreen));
+ }
+
+#ifdef XWIN_MULTIWINDOW
+ /* Notify the worker threads we're exiting */
+ winDeinitMultiWindowWM ();
+#endif
+
+#ifdef HAS_DEVWINDOWS
+ /* Close our handle to our message queue */
+ if (g_fdMessageQueue != WIN_FD_INVALID)
+ {
+ /* Close /dev/windows */
+ close (g_fdMessageQueue);
+
+ /* Set the file handle to invalid */
+ g_fdMessageQueue = WIN_FD_INVALID;
+ }
+#endif
+
+ if (!g_fLogInited) {
+ g_pszLogFile = LogInit (g_pszLogFile, NULL);
+ g_fLogInited = TRUE;
+ }
+ LogClose ();
+
+ /*
+ * At this point we aren't creating any new screens, so
+ * we are guaranteed to not need the DirectDraw functions.
+ */
+ if (g_hmodDirectDraw != NULL)
+ {
+ FreeLibrary (g_hmodDirectDraw);
+ g_hmodDirectDraw = NULL;
+ g_fpDirectDrawCreate = NULL;
+ g_fpDirectDrawCreateClipper = NULL;
+ }
+
+ /* Unload our TrackMouseEvent funtion pointer */
+ if (g_hmodCommonControls != NULL)
+ {
+ FreeLibrary (g_hmodCommonControls);
+ g_hmodCommonControls = NULL;
+ g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA;
+ }
+
+ /* Free concatenated command line */
+ if (g_pszCommandLine)
+ {
+ free (g_pszCommandLine);
+ g_pszCommandLine = NULL;
+ }
+
+ /* Remove our keyboard hook if it is installed */
+ winRemoveKeyboardHookLL ();
+
+ /* Tell Windows that we want to end the app */
+ PostQuitMessage (0);
+}
+
+
+/* See Porting Layer Definition - p. 57 */
+void
+AbortDDX (void)
+{
+ winDebug ("AbortDDX\n");
+ ddxGiveUp ();
+}
+
+#ifdef __CYGWIN__
+/* hasmntopt is currently not implemented for cygwin */
+static const char *winCheckMntOpt(const struct mntent *mnt, const char *opt)
+{
+ const char *s;
+ size_t len;
+ if (mnt == NULL)
+ return NULL;
+ if (opt == NULL)
+ return NULL;
+ if (mnt->mnt_opts == NULL)
+ return NULL;
+
+ len = strlen(opt);
+ s = strstr(mnt->mnt_opts, opt);
+ if (s == NULL)
+ return NULL;
+ if ((s == mnt->mnt_opts || *(s-1) == ',') && (s[len] == 0 || s[len] == ','))
+ return (char *)opt;
+ return NULL;
+}
+
+static void
+winCheckMount(void)
+{
+ FILE *mnt;
+ struct mntent *ent;
+
+ enum { none = 0, sys_root, user_root, sys_tmp, user_tmp }
+ level = none, curlevel;
+ BOOL binary = TRUE;
+
+ mnt = setmntent("/etc/mtab", "r");
+ if (mnt == NULL)
+ {
+ ErrorF("setmntent failed");
+ return;
+ }
+
+ while ((ent = getmntent(mnt)) != NULL)
+ {
+ BOOL system = (winCheckMntOpt(ent, "user") != NULL);
+ BOOL root = (strcmp(ent->mnt_dir, "/") == 0);
+ BOOL tmp = (strcmp(ent->mnt_dir, "/tmp") == 0);
+
+ if (system)
+ {
+ if (root)
+ curlevel = sys_root;
+ else if (tmp)
+ curlevel = sys_tmp;
+ else
+ continue;
+ }
+ else
+ {
+ if (root)
+ curlevel = user_root;
+ else if (tmp)
+ curlevel = user_tmp;
+ else
+ continue;
+ }
+
+ if (curlevel <= level)
+ continue;
+ level = curlevel;
+
+ if ((winCheckMntOpt(ent, "binary") == NULL) ||
+ (winCheckMntOpt(ent, "binmode") == NULL))
+ binary = 0;
+ else
+ binary = 1;
+ }
+
+ if (endmntent(mnt) != 1)
+ {
+ ErrorF("endmntent failed");
+ return;
+ }
+
+#ifdef WINDBG
+ if (!binary)
+ winDebug("/tmp mounted in textmode\n");
+#endif
+}
+#else
+static void
+winCheckMount(void)
+{
+}
+#endif
+
+#ifdef RELOCATE_PROJECTROOT
+const char *
+winGetBaseDir(void)
+{
+ static BOOL inited = FALSE;
+ static char buffer[MAX_PATH];
+ if (!inited)
+ {
+ char *fendptr;
+ HMODULE module = GetModuleHandle(NULL);
+ DWORD size = GetModuleFileName(module, buffer, sizeof(buffer));
+ if (sizeof(buffer) > 0)
+ buffer[sizeof(buffer)-1] = 0;
+
+ fendptr = buffer + size;
+ while (fendptr > buffer)
+ {
+ if (*fendptr == '\\' || *fendptr == '/')
+ {
+ *fendptr = 0;
+ break;
+ }
+ fendptr--;
+ }
+ inited = TRUE;
+ }
+ return buffer;
+}
+#endif
+
+static void
+winFixupPaths (void)
+{
+ BOOL changed_fontpath = FALSE;
+ MessageType font_from = X_DEFAULT;
+#ifdef RELOCATE_PROJECTROOT
+ const char *basedir = winGetBaseDir();
+ size_t basedirlen = strlen(basedir);
+#endif
+
+#ifdef READ_FONTDIRS
+ {
+ /* Open fontpath configuration file */
+#if defined WIN32 && defined __MINGW32__
+ static Bool once = False;
+ char buffer[MAX_PATH];
+ snprintf(buffer, sizeof(buffer), "%s\\font-dirs", basedir);
+ buffer[sizeof(buffer)-1] = 0;
+ FILE *fontdirs = fopen(buffer, "rt");
+ if (once) fontdirs = NULL;
+ else once = True;
+#else
+ FILE *fontdirs = fopen(ETCX11DIR "/font-dirs", "rt");
+#endif
+ if (fontdirs != NULL)
+ {
+ char buffer[256];
+ int needs_sep = TRUE;
+ int comment_block = FALSE;
+
+ /* get defautl fontpath */
+ char *fontpath = xstrdup(defaultFontPath);
+ size_t size = strlen(fontpath);
+
+ /* read all lines */
+ while (!feof(fontdirs))
+ {
+ size_t blen;
+ char *hashchar;
+ char *str;
+ int has_eol = FALSE;
+
+ /* read one line */
+ str = fgets(buffer, sizeof(buffer), fontdirs);
+ if (str == NULL) /* stop on error or eof */
+ break;
+
+ if (strchr(str, '\n') != NULL)
+ has_eol = TRUE;
+
+ /* check if block is continued comment */
+ if (comment_block)
+ {
+ /* ignore all input */
+ *str = 0;
+ blen = 0;
+ if (has_eol) /* check if line ended in this block */
+ comment_block = FALSE;
+ }
+ else
+ {
+ /* find comment character. ignore all trailing input */
+ hashchar = strchr(str, '#');
+ if (hashchar != NULL)
+ {
+ *hashchar = 0;
+ if (!has_eol) /* mark next block as continued comment */
+ comment_block = TRUE;
+ }
+ }
+
+ /* strip whitespaces from beginning */
+ while (*str == ' ' || *str == '\t')
+ str++;
+
+ /* get size, strip whitespaces from end */
+ blen = strlen(str);
+ while (blen > 0 && (str[blen-1] == ' ' ||
+ str[blen-1] == '\t' || str[blen-1] == '\n'))
+ {
+ str[--blen] = 0;
+ }
+
+ /* still something left to add? */
+ if (blen > 0)
+ {
+ size_t newsize = size + blen;
+ /* reserve one character more for ',' */
+ if (needs_sep)
+ newsize++;
+
+ /* allocate memory */
+ if (fontpath == NULL)
+ fontpath = malloc(newsize+1);
+ else
+ fontpath = realloc(fontpath, newsize+1);
+
+ /* add separator */
+ if (needs_sep)
+ {
+ fontpath[size] = ',';
+ size++;
+ needs_sep = FALSE;
+ }
+
+ /* mark next line as new entry */
+ if (has_eol)
+ needs_sep = TRUE;
+
+ /* add block */
+ strncpy(fontpath + size, str, blen);
+ fontpath[newsize] = 0;
+ size = newsize;
+ }
+ }
+
+ /* cleanup */
+ fclose(fontdirs);
+ defaultFontPath = xstrdup(fontpath);
+ free(fontpath);
+ changed_fontpath = TRUE;
+ font_from = X_CONFIG;
+ }
+ }
+#endif /* READ_FONTDIRS */
+#ifdef RELOCATE_PROJECTROOT
+ {
+ const char *libx11dir = PROJECTROOT "/lib/X11";
+ size_t libx11dir_len = strlen(libx11dir);
+ char *newfp = NULL;
+ size_t newfp_len = 0;
+ const char *endptr, *ptr, *oldptr = defaultFontPath;
+
+ endptr = oldptr + strlen(oldptr);
+ ptr = strchr(oldptr, ',');
+ if (ptr == NULL)
+ ptr = endptr;
+ while (ptr != NULL)
+ {
+ size_t oldfp_len = (ptr - oldptr);
+ size_t newsize = oldfp_len;
+ char *newpath = malloc(newsize + 1);
+ strncpy(newpath, oldptr, newsize);
+ newpath[newsize] = 0;
+
+
+ if (strncmp(libx11dir, newpath, libx11dir_len) == 0)
+ {
+ char *compose;
+ newsize = newsize - libx11dir_len + basedirlen;
+ compose = malloc(newsize + 1);
+ strcpy(compose, basedir);
+ strncat(compose, newpath + libx11dir_len, newsize - basedirlen);
+ compose[newsize] = 0;
+ free(newpath);
+ newpath = compose;
+ }
+
+ oldfp_len = newfp_len;
+ if (oldfp_len > 0)
+ newfp_len ++; /* space for separator */
+ newfp_len += newsize;
+
+ if (newfp == NULL)
+ newfp = malloc(newfp_len + 1);
+ else
+ newfp = realloc(newfp, newfp_len + 1);
+
+ if (oldfp_len > 0)
+ {
+ strcpy(newfp + oldfp_len, ",");
+ oldfp_len++;
+ }
+ strcpy(newfp + oldfp_len, newpath);
+
+ free(newpath);
+
+ if (*ptr == 0)
+ {
+ oldptr = ptr;
+ ptr = NULL;
+ } else
+ {
+ oldptr = ptr + 1;
+ ptr = strchr(oldptr, ',');
+ if (ptr == NULL)
+ ptr = endptr;
+ }
+ }
+
+ defaultFontPath = xstrdup(newfp);
+ free(newfp);
+ changed_fontpath = TRUE;
+ }
+#endif /* RELOCATE_PROJECTROOT */
+ if (changed_fontpath)
+ winDebug ("FontPath set to \"%s\"\n", defaultFontPath);
+
+#ifdef RELOCATE_PROJECTROOT
+ if (getenv("XKEYSYMDB") == NULL)
+ {
+ char buffer[MAX_PATH];
+ snprintf(buffer, sizeof(buffer), "XKEYSYMDB=%s\\XKeysymDB",
+ basedir);
+ buffer[sizeof(buffer)-1] = 0;
+ putenv(buffer);
+ }
+ if (getenv("XERRORDB") == NULL)
+ {
+ char buffer[MAX_PATH];
+ snprintf(buffer, sizeof(buffer), "XERRORDB=%s\\XErrorDB",
+ basedir);
+ buffer[sizeof(buffer)-1] = 0;
+ putenv(buffer);
+ }
+ if (getenv("XLOCALEDIR") == NULL)
+ {
+ char buffer[MAX_PATH];
+ snprintf(buffer, sizeof(buffer), "XLOCALEDIR=%s\\locale",
+ basedir);
+ buffer[sizeof(buffer)-1] = 0;
+ putenv(buffer);
+ }
+ if (getenv("XHOSTPREFIX") == NULL)
+ {
+ char buffer[MAX_PATH];
+ snprintf(buffer, sizeof(buffer), "XHOSTPREFIX=%s\\X",
+ basedir);
+ buffer[sizeof(buffer)-1] = 0;
+ putenv(buffer);
+ }
+ if (getenv("HOME") == NULL)
+ {
+ HMODULE shfolder;
+ SHGETFOLDERPATHPROC shgetfolderpath = NULL;
+ char buffer[MAX_PATH + 5];
+ strncpy(buffer, "HOME=", 5);
+
+ /* Try to load SHGetFolderPath from shfolder.dll and shell32.dll */
+
+ shfolder = LoadLibrary("shfolder.dll");
+ /* fallback to shell32.dll */
+ if (shfolder == NULL)
+ shfolder = LoadLibrary("shell32.dll");
+
+ /* resolve SHGetFolderPath */
+ if (shfolder != NULL)
+ shgetfolderpath = (SHGETFOLDERPATHPROC)GetProcAddress(shfolder, "SHGetFolderPathA");
+
+ /* query appdata directory */
+ if (shgetfolderpath &&
+ shgetfolderpath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0,
+ buffer + 5) == 0)
+ {
+ putenv(buffer);
+ } else
+ {
+ ErrorF ("Can not determine HOME directory\n");
+ }
+ if (shfolder != NULL)
+ FreeLibrary(shfolder);
+ }
+ if (!g_fLogFileChanged) {
+ static char buffer[MAX_PATH];
+ DWORD size = GetTempPath(sizeof(buffer), buffer);
+ if (size && size < sizeof(buffer))
+ {
+ snprintf(buffer + size, sizeof(buffer) - size,
+ "VCXSrv.%s.log", display);
+ buffer[sizeof(buffer)-1] = 0;
+ g_pszLogFile = buffer;
+ GetLongPathName(buffer, buffer, MAX_PATH);
+ winDebug ("Logfile set to \"%s\"\n", g_pszLogFile);
+ }
+ }
+ {
+ static char xkbbasedir[MAX_PATH];
+
+ snprintf(xkbbasedir, sizeof(xkbbasedir), "%s\\xkbdata", basedir);
+ if (sizeof(xkbbasedir) > 0)
+ xkbbasedir[sizeof(xkbbasedir)-1] = 0;
+ XkbBaseDirectory = xkbbasedir;
+ XkbBinDirectory = basedir;
+ }
+#endif /* RELOCATE_PROJECTROOT */
+}
+
+void
+OsVendorInit (void)
+{
+ /* Re-initialize global variables on server reset */
+ winInitializeGlobals ();
+
+ winFixupPaths();
+
+#ifdef DDXOSVERRORF
+ if (!OsVendorVErrorFProc)
+ OsVendorVErrorFProc = OsVendorVErrorF;
+#endif
+
+ if (!g_fLogInited) {
+ /* keep this order. If LogInit fails it calls Abort which then calls
+ * ddxGiveUp where LogInit is called again and creates an infinite
+ * recursion. If we set g_fLogInited to TRUE before the init we
+ * avoid the second call
+ */
+ g_fLogInited = TRUE;
+ g_pszLogFile = LogInit (g_pszLogFile, NULL);
+ }
+ LogSetParameter (XLOG_FLUSH, 1);
+ LogSetParameter (XLOG_VERBOSITY, g_iLogVerbose);
+ LogSetParameter (XLOG_FILE_VERBOSITY, g_iLogVerbose);
+
+ /* Log the version information */
+ if (serverGeneration == 1)
+ winLogVersionInfo ();
+
+ winCheckMount();
+
+ /* Add a default screen if no screens were specified */
+ if (g_iNumScreens == 0)
+ {
+ winDebug ("OsVendorInit - Creating bogus screen 0\n");
+
+ /*
+ * We need to initialize default screens if no arguments
+ * were processed. Otherwise, the default screens would
+ * already have been initialized by ddxProcessArgument ().
+ */
+ winInitializeDefaultScreens ();
+
+ /*
+ * Add a screen 0 using the defaults set by
+ * winInitializeDefaultScreens () and any additional parameters
+ * processed by ddxProcessArgument ().
+ */
+ g_iNumScreens = 1;
+ g_iLastScreen = 0;
+
+ /* We have to flag this as an explicit screen, even though it isn't */
+ g_ScreenInfo[0].fExplicitScreen = TRUE;
+ }
+}
+
+
+static void
+winUseMsg (void)
+{
+ ErrorF ("-depth bits_per_pixel\n"
+ "\tSpecify an optional bitdepth to use in fullscreen mode\n"
+ "\twith a DirectDraw engine.\n");
+
+ ErrorF ("-emulate3buttons [timeout]\n"
+ "\tEmulate 3 button mouse with an optional timeout in\n"
+ "\tmilliseconds.\n");
+
+ ErrorF ("-engine engine_type_id\n"
+ "\tOverride the server's automatically selected engine type:\n"
+ "\t\t1 - Shadow GDI\n"
+ "\t\t2 - Shadow DirectDraw\n"
+ "\t\t4 - Shadow DirectDraw4 Non-Locking\n"
+#ifdef XWIN_NATIVEGDI
+ "\t\t16 - Native GDI - experimental\n"
+#endif
+ );
+
+ ErrorF ("-fullscreen\n"
+ "\tRun the server in fullscreen mode.\n");
+
+ ErrorF ("-refresh rate_in_Hz\n"
+ "\tSpecify an optional refresh rate to use in fullscreen mode\n"
+ "\twith a DirectDraw engine.\n");
+
+ ErrorF ("-screen scr_num [width height [x y] | [[WxH[+X+Y]][@m]] ]\n"
+ "\tEnable screen scr_num and optionally specify a width and\n"
+ "\theight and initial position for that screen. Additionally\n"
+ "\ta monitor number can be specified to start the server on,\n"
+ "\tat which point, all coordinates become relative to that\n"
+ "\tmonitor (Not for Windows NT4 and 95). Examples:\n"
+ "\t -screen 0 800x600+100+100@2 ; 2nd monitor offset 100,100 size 800x600\n"
+ "\t -screen 0 1024x768@3 ; 3rd monitor size 1024x768\n"
+ "\t -screen 0 @1 ; on 1st monitor using its full resolution (the default)\n");
+
+ ErrorF ("-lesspointer\n"
+ "\tHide the windows mouse pointer when it is over an inactive\n"
+ "\t" PROJECT_NAME " window. This prevents ghost cursors appearing where\n"
+ "\tthe Windows cursor is drawn overtop of the X cursor\n");
+
+ ErrorF ("-nodecoration\n"
+ "\tDo not draw a window border, title bar, etc. Windowed\n"
+ "\tmode only.\n");
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+ ErrorF ("-mwextwm\n"
+ "\tRun the server in multi-window external window manager mode.\n");
+
+ ErrorF ("-internalwm\n"
+ "\tRun the internal window manager.\n");
+#endif
+
+ ErrorF ("-rootless\n"
+ "\tRun the server in rootless mode.\n");
+
+#ifdef XWIN_MULTIWINDOW
+ ErrorF ("-multiwindow\n"
+ "\tRun the server in multi-window mode.\n");
+#endif
+
+ ErrorF ("-multiplemonitors\n"
+ "\tEXPERIMENTAL: Use the entire virtual screen if multiple\n"
+ "\tmonitors are present.\n");
+
+#ifdef XWIN_CLIPBOARD
+ ErrorF ("-[no]clipboard\n"
+ "\tEnable [disable] the clipboard integration. Default is enabled.\n");
+
+ ErrorF ("-nounicodeclipboard\n"
+ "\tDo not use Unicode clipboard even if NT-based platform.\n");
+#endif
+
+ ErrorF ("-scrollbars\n"
+ "\tIn windowed mode, allow screens bigger than the Windows desktop.\n"
+ "\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"
+ "\tupdated region. Currently supported only by `-engine 1'.\n");
+
+#ifdef XWIN_EMULATEPSEUDO
+ ErrorF ("-emulatepseudo\n"
+ "\tCreate a depth 8 PseudoColor visual when running in\n"
+ "\tdepths 15, 16, 24, or 32, collectively known as TrueColor\n"
+ "\tdepths. The PseudoColor visual does not have correct colors,\n"
+ "\tand it may crash, but it at least allows you to run your\n"
+ "\tapplication in TrueColor modes.\n");
+#endif
+
+ ErrorF ("-[no]unixkill\n"
+ "\tCtrl+Alt+Backspace exits the X Server.\n");
+
+ ErrorF ("-[no]winkill\n"
+ "\tAlt+F4 exits the X Server.\n");
+
+#ifdef XWIN_XF86CONFIG
+ ErrorF ("-config\n"
+ "\tSpecify a configuration file.\n");
+
+ ErrorF ("-keyboard\n"
+ "\tSpecify a keyboard device from the configuration file.\n");
+#endif
+
+ ErrorF ("-xkbrules XKBRules\n"
+ "\tEquivalent to XKBRules in XF86Config files.\n");
+
+ ErrorF ("-xkbmodel XKBModel\n"
+ "\tEquivalent to XKBModel in XF86Config files.\n");
+
+ ErrorF ("-xkblayout XKBLayout\n"
+ "\tEquivalent to XKBLayout in XF86Config files.\n"
+ "\tFor example: -xkblayout de\n");
+
+ ErrorF ("-xkbvariant XKBVariant\n"
+ "\tEquivalent to XKBVariant in XF86Config files.\n"
+ "\tFor example: -xkbvariant nodeadkeys\n");
+
+ ErrorF ("-xkboptions XKBOptions\n"
+ "\tEquivalent to XKBOptions in XF86Config files.\n");
+
+ ErrorF ("-logfile filename\n"
+ "\tWrite logmessages to <filename>.\n");
+
+ ErrorF ("-logverbose verbosity\n"
+ "\tSet the verbosity of logmessages. [NOTE: Only a few messages\n"
+ "\trespect the settings yet]\n"
+ "\t\t0 - only print fatal error.\n"
+ "\t\t1 - print additional configuration information.\n"
+ "\t\t2 - print additional runtime information [default].\n"
+ "\t\t3 - print debugging and tracing information.\n");
+
+ ErrorF ("-[no]keyhook\n"
+ "\tGrab special windows key combinations like Alt-Tab or the Menu "
+ "key.\n These keys are discarded by default.\n");
+
+ ErrorF ("-swcursor\n"
+ "\tDisable the usage of the windows cursor and use the X11 software "
+ "cursor instead\n");
+}
+
+/* See Porting Layer Definition - p. 57 */
+void
+ddxUseMsg(void)
+{
+ /* Set a flag so that FatalError won't give duplicate warning message */
+ g_fSilentFatalError = TRUE;
+
+ winUseMsg();
+
+ /* Log file will not be opened for UseMsg unless we open it now */
+ if (!g_fLogInited) {
+ g_pszLogFile = LogInit (g_pszLogFile, NULL);
+ g_fLogInited = TRUE;
+ }
+ LogClose ();
+
+ /* Notify user where UseMsg text can be found.*/
+ if (!g_fNoHelpMessageBox)
+ winMessageBoxF ("The " PROJECT_NAME " help text has been printed to "
+ "%s.\n"
+ "Please open %s to read the help text.\n",
+ MB_ICONINFORMATION, g_pszLogFile, g_pszLogFile);
+}
+
+/* See Porting Layer Definition - p. 20 */
+/*
+ * Do any global initialization, then initialize each screen.
+ *
+ * NOTE: We use ddxProcessArgument, so we don't need to touch argc and argv
+ */
+
+void
+InitOutput (ScreenInfo *screenInfo, int argc, char *argv[])
+{
+ int i;
+
+ /* Log the command line */
+ winLogCommandLine (argc, argv);
+
+ winDebug ("InitOutput\n");
+
+ /* Validate command-line arguments */
+ if (serverGeneration == 1 && !winValidateArgs ())
+ {
+ FatalError ("InitOutput - Invalid command-line arguments found. "
+ "Exiting.\n");
+ }
+
+ /* Check for duplicate invocation on same display number.*/
+ if (serverGeneration == 1 && !winCheckDisplayNumber ())
+ {
+ if (g_fSilentDupError)
+ g_fSilentFatalError = TRUE;
+ FatalError ("InitOutput - Duplicate invocation on display "
+ "number: %s. Exiting.\n", display);
+ }
+
+#ifdef XWIN_XF86CONFIG
+ /* Try to read the xorg.conf-style configuration file */
+ if (!winReadConfigfile ())
+ ErrorF ("InitOutput - Error reading config file\n");
+#else
+ winConfigFiles ();
+#endif
+
+ /* Load preferences from XWinrc file */
+ LoadPreferences();
+
+ /* Setup global screen info parameters */
+ screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
+ screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
+ screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
+ screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
+ screenInfo->numPixmapFormats = NUMFORMATS;
+
+ /* Describe how we want common pixmap formats padded */
+ for (i = 0; i < NUMFORMATS; i++)
+ {
+ screenInfo->formats[i] = g_PixmapFormats[i];
+ }
+
+ /* Load pointers to DirectDraw functions */
+ winGetDDProcAddresses ();
+
+ /* Detect supported engines */
+ winDetectSupportedEngines ();
+
+ /* Load common controls library */
+ g_hmodCommonControls = LoadLibraryEx ("comctl32.dll", NULL, 0);
+
+ /* Load TrackMouseEvent function pointer */
+ g_fpTrackMouseEvent = GetProcAddress (g_hmodCommonControls,
+ "_TrackMouseEvent");
+ if (g_fpTrackMouseEvent == NULL)
+ {
+ ErrorF ("InitOutput - Could not get pointer to function\n"
+ "\t_TrackMouseEvent in comctl32.dll. Try installing\n"
+ "\tInternet Explorer 3.0 or greater if you have not\n"
+ "\talready.\n");
+
+ /* Free the library since we won't need it */
+ FreeLibrary (g_hmodCommonControls);
+ g_hmodCommonControls = NULL;
+
+ /* Set function pointer to point to no operation function */
+ g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA;
+ }
+
+ /* Store the instance handle */
+ g_hInstance = GetModuleHandle (NULL);
+
+ /* Initialize each screen */
+ for (i = 0; i < g_iNumScreens; ++i)
+ {
+ /* Initialize the screen */
+ if (-1 == AddScreen (winScreenInit, argc, argv))
+ {
+ FatalError ("InitOutput - Couldn't add screen %d", i);
+ }
+ }
+
+#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+
+ /* Generate a cookie used by internal clients for authorization */
+ if (g_fXdmcpEnabled || g_fAuthEnabled)
+ winGenerateAuthorization ();
+
+ /* Perform some one time initialization */
+ if (1 == serverGeneration)
+ {
+ /*
+ * setlocale applies to all threads in the current process.
+ * Apply locale specified in LANG environment variable.
+ */
+ setlocale (LC_ALL, "");
+
+ glx_debugging();
+ }
+#endif
+
+ winDebug ("InitOutput - Returning.\n");
+}
+
+
+/*
+ * winCheckDisplayNumber - Check if another instance of Cygwin/X is
+ * already running on the same display number. If no one exists,
+ * make a mutex to prevent new instances from running on the same display.
+ *
+ * return FALSE if the display number is already used.
+ */
+
+static Bool
+winCheckDisplayNumber (void)
+{
+ int nDisp;
+ HANDLE mutex;
+ char name[MAX_PATH];
+ char * pszPrefix = '\0';
+ OSVERSIONINFO osvi = {0};
+
+ /* Check display range */
+ nDisp = atoi (display);
+ if (nDisp < 0 || nDisp > 59535)
+ {
+ ErrorF ("winCheckDisplayNumber - Bad display number: %d\n", nDisp);
+ return FALSE;
+ }
+
+ /* Set first character of mutex name to null */
+ name[0] = '\0';
+
+ /* Get operating system version information */
+ osvi.dwOSVersionInfoSize = sizeof (osvi);
+ GetVersionEx (&osvi);
+
+ /* Want a mutex shared among all terminals on NT > 4.0 */
+ if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT
+ && osvi.dwMajorVersion >= 5)
+ {
+ pszPrefix = "Global\\";
+ }
+
+ /* Setup Cygwin/X specific part of name */
+ snprintf (name, sizeof(name), "%sCYGWINX_DISPLAY:%d", pszPrefix, nDisp);
+
+ /* Windows automatically releases the mutex when this process exits */
+ mutex = CreateMutex (NULL, FALSE, name);
+ if (!mutex)
+ {
+ LPVOID lpMsgBuf;
+
+ /* Display a fancy error message */
+ FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ GetLastError (),
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR) &lpMsgBuf,
+ 0, NULL);
+ ErrorF ("winCheckDisplayNumber - CreateMutex failed: %s\n",
+ (LPSTR)lpMsgBuf);
+ LocalFree (lpMsgBuf);
+
+ return FALSE;
+ }
+ if (GetLastError () == ERROR_ALREADY_EXISTS)
+ {
+ ErrorF ("winCheckDisplayNumber - "
+ "VCXsrv, Xming or Cygwin/X is already running on display %d\n",
+ nDisp);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/* GLX debugging helpers */
+#include <../glx/glapi.h>
+
+static
+void warn_func(void * p1, const char *format, ...) {
+ va_list v;
+ va_start(v, format);
+ vfprintf(stderr, format, v);
+ va_end(v);
+ fprintf(stderr,"\n");
+}
+
+static
+void glx_debugging(void)
+{
+ _glapi_set_warning_func(warn_func);
+ _glapi_noop_enable_warnings(TRUE);
+}
diff --git a/xorg-server/hw/xwin/XWin.man.pre b/xorg-server/hw/xwin/XWin.man.pre index 9649e2e60..0bad65c60 100644 --- a/xorg-server/hw/xwin/XWin.man.pre +++ b/xorg-server/hw/xwin/XWin.man.pre @@ -80,10 +80,9 @@ In addition to the normal server options described in the \fIXserver(1)\fP manual page, \fIXWin\fP accepts the following command line switches, \fIall\fP of which are optional: .TP 8 -.B \-clipboard -Enables the integration -between the Cygwin/X clipboard and Windows clipboard. Do not use in -conjunction with the \fIxwinclip\fP program. +.B \-[no]clipboard +Enables [disables] the integration between the Cygwin/X clipboard and +Windows clipboard. The default is enabled. .TP 8 .B "\-clipupdates \fInum_boxes\fP" Specify an optional threshold, above which the boxes in a shadow diff --git a/xorg-server/hw/xwin/XWinrc.man.pre b/xorg-server/hw/xwin/XWinrc.man.pre index 4fb436ddd..5c1fb979b 100644 --- a/xorg-server/hw/xwin/XWinrc.man.pre +++ b/xorg-server/hw/xwin/XWinrc.man.pre @@ -65,8 +65,13 @@ system tray area. .TP 8 .B SILENTEXIT The \fBSILENTEXIT\fP keyword, which takes no parameters, disables the -exit confirmation dialog. +exit confirmation dialog if no clients are connected. +.TP 8 +.B FORCEEXIT +The \fBFORCEEXIT\fP keyword, which takes no parameters, disables the +exit confirmation dialog always. Unsaved client work may be lost but +this may be useful if you want no dialogs. .SH Menu instructions .TP 8 diff --git a/xorg-server/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc b/xorg-server/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc index d9c2d4210..1de6e2ab0 100644 --- a/xorg-server/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc +++ b/xorg-server/hw/xwin/_usr_X11R6_lib_X11_system.XWinrc @@ -119,7 +119,7 @@ SysMenu { # "xterm" "uninstall.ico" # } -# SilentExit +SilentExit DEBUG "Done parsing the configuration file..." diff --git a/xorg-server/hw/xwin/win.h b/xorg-server/hw/xwin/win.h index 8470cef6b..48f7d65f5 100644 --- a/xorg-server/hw/xwin/win.h +++ b/xorg-server/hw/xwin/win.h @@ -1,1430 +1,1429 @@ -/* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of the XFree86 Project - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from the XFree86 Project. - * - * Authors: Dakshinamurthy Karra - * Suhaib M Siddiqi - * Peter Busch - * Harold L Hunt II - * Kensuke Matsuzaki - */ - -#ifndef _WIN_H_ -#define _WIN_H_ - -#ifndef NO -#define NO 0 -#endif -#ifndef YES -#define YES 1 -#endif - -/* WM_XBUTTON Messages. They should go into w32api. */ -#ifndef WM_XBUTTONDOWN -# define WM_XBUTTONDOWN 523 -#endif -#ifndef WM_XBUTTONUP -# define WM_XBUTTONUP 524 -#endif -#ifndef WM_XBUTTONDBLCLK -# define WM_XBUTTONDBLCLK 525 -#endif - - -#define WIN_DEFAULT_BPP 0 -#define WIN_DEFAULT_WHITEPIXEL 255 -#define WIN_DEFAULT_BLACKPIXEL 0 -#define WIN_DEFAULT_LINEBIAS 0 -#define WIN_DEFAULT_E3B_TIME 50 /* milliseconds */ -#define WIN_DEFAULT_DPI 75 -#define WIN_DEFAULT_REFRESH 0 -#define WIN_DEFAULT_WIN_KILL TRUE -#define WIN_DEFAULT_UNIX_KILL FALSE -#define WIN_DEFAULT_CLIP_UPDATES_NBOXES 0 -#ifdef XWIN_EMULATEPSEUDO -#define WIN_DEFAULT_EMULATE_PSEUDO FALSE -#endif -#define WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH FALSE - -#define WIN_DIB_MAXIMUM_SIZE 0x08000000 /* 16 MB on Windows 95, 98, Me */ -#define WIN_DIB_MAXIMUM_SIZE_MB (WIN_DIB_MAXIMUM_SIZE / 8 / 1024 / 1024) - -/* - * Windows only supports 256 color palettes - */ -#define WIN_NUM_PALETTE_ENTRIES 256 - -/* - * Number of times to call Restore in an attempt to restore the primary surface - */ -#define WIN_REGAIN_SURFACE_RETRIES 1 - -/* - * Build a supported display depths mask by shifting one to the left - * by the number of bits in the supported depth. - */ -#define WIN_SUPPORTED_BPPS ( (1 << (32 - 1)) | (1 << (24 - 1)) \ - | (1 << (16 - 1)) | (1 << (15 - 1)) \ - | (1 << ( 8 - 1))) -#define WIN_CHECK_DEPTH YES - -/* - * Timer IDs for WM_TIMER - */ -#define WIN_E3B_TIMER_ID 1 -#define WIN_POLLING_MOUSE_TIMER_ID 2 - -#define MOUSE_POLLING_INTERVAL 50 - -#define WIN_E3B_OFF -1 -#define WIN_FD_INVALID -1 - -#define WIN_SERVER_NONE 0x0L /* 0 */ -#define WIN_SERVER_SHADOW_GDI 0x1L /* 1 */ -#define WIN_SERVER_SHADOW_DD 0x2L /* 2 */ -#define WIN_SERVER_SHADOW_DDNL 0x4L /* 4 */ -#ifdef XWIN_PRIMARYFB -#define WIN_SERVER_PRIMARY_DD 0x8L /* 8 */ -#endif -#ifdef XWIN_NATIVEGDI -# define WIN_SERVER_NATIVE_GDI 0x10L /* 16 */ -#endif - -#define AltMapIndex Mod1MapIndex -#define NumLockMapIndex Mod2MapIndex -#define AltLangMapIndex Mod3MapIndex -#define KanaMapIndex Mod4MapIndex -#define ScrollLockMapIndex Mod5MapIndex - -#define WIN_MOD_LALT 0x00000001 -#define WIN_MOD_RALT 0x00000002 -#define WIN_MOD_LCONTROL 0x00000004 -#define WIN_MOD_RCONTROL 0x00000008 - -#define WIN_24BPP_MASK_RED 0x00FF0000 -#define WIN_24BPP_MASK_GREEN 0x0000FF00 -#define WIN_24BPP_MASK_BLUE 0x000000FF - -#define WIN_MAX_KEYS_PER_KEY 4 - -#include <sys/types.h> -#include <sys/stat.h> -#include <stdio.h> - -#include <errno.h> -#if defined(XWIN_MULTIWINDOWEXTWM) || defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) -#define HANDLE void * -#ifdef _MSC_VER -typedef int pid_t; -#endif -#include <pthread.h> -#undef HANDLE -#endif - -#ifdef HAS_MMAP -#include <sys/mman.h> -#ifndef MAP_FILE -#define MAP_FILE 0 -#endif /* MAP_FILE */ -#endif /* HAS_MMAP */ - -#include <X11/X.h> -#include <X11/Xproto.h> -#include <X11/Xos.h> -#include <X11/Xprotostr.h> -#include "scrnintstr.h" -#include "pixmapstr.h" -#include "pixmap.h" -#include "region.h" -#include "gcstruct.h" -#include "colormap.h" -#include "colormapst.h" -#include "miscstruct.h" -#include "servermd.h" -#include "windowstr.h" -#include "mi.h" -#include "micmap.h" -#include "mifillarc.h" -#include "mifpoly.h" -#include "mibstore.h" -#include "input.h" -#include "mipointer.h" -#include "X11/keysym.h" -#include "mibstore.h" -#include "micoord.h" -#include "dix.h" -#include "miline.h" -#include "shadow.h" -#include "fb.h" -#include "rootless.h" - -#ifdef RENDER -#include "mipict.h" -#include "picturestr.h" -#endif - -#ifdef RANDR -#include "randrstr.h" -#endif - -/* - * Windows headers - */ -#include "winms.h" -#include "./winresource.h" - - -/* - * Define Windows constants - */ - -#define WM_TRAYICON (WM_USER + 1000) -#define WM_INIT_SYS_MENU (WM_USER + 1001) -#define WM_GIVEUP (WM_USER + 1002) - - -/* Local includes */ -#include "winwindow.h" -#include "winmsg.h" - -#define PROFILEPOINT(point,thresh)\ -{\ -static unsigned int PROFPT##point = 0;\ -if (++PROFPT##point % thresh == 0)\ -ErrorF (#point ": PROFILEPOINT hit %u times\n", PROFPT##point);\ -} - - -/* We use xor this macro for detecting toggle key state changes */ -#define WIN_XOR(a,b) ((!(a) && (b)) || ((a) && !(b))) - -#define DEFINE_ATOM_HELPER(func,atom_name) \ -static Atom func (void) { \ - static int generation; \ - static Atom atom; \ - if (generation != serverGeneration) { \ - generation = serverGeneration; \ - atom = MakeAtom (atom_name, strlen (atom_name), TRUE); \ - } \ - return atom; \ -} - -/* - * Typedefs for engine dependent function pointers - */ - -typedef Bool (*winAllocateFBProcPtr)(ScreenPtr); - -typedef void (*winShadowUpdateProcPtr)(ScreenPtr, shadowBufPtr); - -typedef Bool (*winCloseScreenProcPtr)(int, ScreenPtr); - -typedef Bool (*winInitVisualsProcPtr)(ScreenPtr); - -typedef Bool (*winAdjustVideoModeProcPtr)(ScreenPtr); - -typedef Bool (*winCreateBoundingWindowProcPtr)(ScreenPtr); - -typedef Bool (*winFinishScreenInitProcPtr)(int, ScreenPtr, int, char **); - -typedef Bool (*winBltExposedRegionsProcPtr)(ScreenPtr); - -typedef Bool (*winActivateAppProcPtr)(ScreenPtr); - -typedef Bool (*winRedrawScreenProcPtr)(ScreenPtr pScreen); - -typedef Bool (*winRealizeInstalledPaletteProcPtr)(ScreenPtr pScreen); - -typedef Bool (*winInstallColormapProcPtr)(ColormapPtr pColormap); - -typedef Bool (*winStoreColorsProcPtr)(ColormapPtr pmap, - int ndef, xColorItem *pdefs); - -typedef Bool (*winCreateColormapProcPtr)(ColormapPtr pColormap); - -typedef Bool (*winDestroyColormapProcPtr)(ColormapPtr pColormap); - -typedef Bool (*winHotKeyAltTabProcPtr)(ScreenPtr); - -typedef Bool (*winCreatePrimarySurfaceProcPtr)(ScreenPtr); - -typedef Bool (*winReleasePrimarySurfaceProcPtr)(ScreenPtr); - -typedef Bool (*winFinishCreateWindowsWindowProcPtr)(WindowPtr pWin); - -typedef Bool (*winCreateScreenResourcesProc)(ScreenPtr); - -/* Typedef for DIX wrapper functions */ -typedef int (*winDispatchProcPtr) (ClientPtr); - - -/* - * GC (graphics context) privates - */ - -typedef struct -{ - HDC hdc; - HDC hdcMem; -} winPrivGCRec, *winPrivGCPtr; - - -/* - * Pixmap privates - */ - -typedef struct -{ - HDC hdcSelected; - HBITMAP hBitmap; - BYTE *pbBits; - DWORD dwScanlineBytes; - BITMAPINFOHEADER *pbmih; -} winPrivPixmapRec, *winPrivPixmapPtr; - - -/* - * Colormap privates - */ - -typedef struct -{ - HPALETTE hPalette; - LPDIRECTDRAWPALETTE lpDDPalette; - RGBQUAD rgbColors[WIN_NUM_PALETTE_ENTRIES]; - PALETTEENTRY peColors[WIN_NUM_PALETTE_ENTRIES]; -} winPrivCmapRec, *winPrivCmapPtr; - -/* - * Windows Cursor handling. - */ - -typedef struct { - /* from GetSystemMetrics */ - int sm_cx; - int sm_cy; - - BOOL visible; - HCURSOR handle; - QueryBestSizeProcPtr QueryBestSize; - miPointerSpriteFuncPtr spriteFuncs; -} winCursorRec; - -/* - * Screen information structure that we need before privates are available - * in the server startup sequence. - */ - -typedef struct -{ - ScreenPtr pScreen; - - /* Did the user specify a height and width? */ - Bool fUserGaveHeightAndWidth; - - DWORD dwScreen; - DWORD dwUserWidth; - DWORD dwUserHeight; - DWORD dwWidth; - DWORD dwHeight; - DWORD dwWidth_mm; - DWORD dwHeight_mm; - DWORD dwPaddedWidth; - - /* Did the user specify a screen position? */ - Bool fUserGavePosition; - DWORD dwInitialX; - DWORD dwInitialY; - - /* - * dwStride is the number of whole pixels that occupy a scanline, - * including those pixels that are not displayed. This is basically - * a rounding up of the width. - */ - DWORD dwStride; - - /* Offset of the screen in the window when using scrollbars */ - DWORD dwXOffset; - DWORD dwYOffset; - - DWORD dwBPP; - DWORD dwDepth; - DWORD dwRefreshRate; - char *pfb; - DWORD dwEngine; - DWORD dwEnginePreferred; - DWORD dwClipUpdatesNBoxes; -#ifdef XWIN_EMULATEPSEUDO - Bool fEmulatePseudo; -#endif - Bool fFullScreen; - Bool fDecoration; -#ifdef XWIN_MULTIWINDOWEXTWM - Bool fMWExtWM; - Bool fInternalWM; - Bool fAnotherWMRunning; -#endif - Bool fRootless; -#ifdef XWIN_MULTIWINDOW - Bool fMultiWindow; -#endif -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - Bool fMultiMonitorOverride; -#endif - Bool fMultipleMonitors; - Bool fLessPointer; - Bool fScrollbars; - Bool fNoTrayIcon; - int iE3BTimeout; - /* Windows (Alt+F4) and Unix (Ctrl+Alt+Backspace) Killkey */ - Bool fUseWinKillKey; - Bool fUseUnixKillKey; - Bool fIgnoreInput; - - /* Did the user explicitly set this screen? */ - Bool fExplicitScreen; -} winScreenInfo, *winScreenInfoPtr; - - -/* - * Screen privates - */ - -typedef struct _winPrivScreenRec -{ - winScreenInfoPtr pScreenInfo; - - Bool fEnabled; - Bool fClosed; - Bool fActive; - Bool fBadDepth; - - int iDeltaZ; - - int iConnectedClients; - - CloseScreenProcPtr CloseScreen; - - DWORD dwRedMask; - DWORD dwGreenMask; - DWORD dwBlueMask; - DWORD dwBitsPerRGB; - - DWORD dwModeKeyStates; - - /* Handle to icons that must be freed */ - HICON hiconNotifyIcon; - - /* Last width, height, and depth of the Windows display */ - DWORD dwLastWindowsWidth; - DWORD dwLastWindowsHeight; - DWORD dwLastWindowsBitsPixel; - - /* Palette management */ - ColormapPtr pcmapInstalled; - - /* Pointer to the root visual so we only have to look it up once */ - VisualPtr pRootVisual; - - /* 3 button emulation variables */ - int iE3BCachedPress; - Bool fE3BFakeButton2Sent; - - /* Privates used by shadow fb GDI server */ - HBITMAP hbmpShadow; - HDC hdcScreen; - HDC hdcShadow; - HWND hwndScreen; - - /* Privates used by shadow fb and primary fb DirectDraw servers */ - LPDIRECTDRAW pdd; - LPDIRECTDRAWSURFACE2 pddsPrimary; - LPDIRECTDRAW2 pdd2; - - /* Privates used by shadow fb DirectDraw server */ - LPDIRECTDRAWSURFACE2 pddsShadow; - LPDDSURFACEDESC pddsdShadow; - - /* Privates used by primary fb DirectDraw server */ - LPDIRECTDRAWSURFACE2 pddsOffscreen; - LPDDSURFACEDESC pddsdOffscreen; - LPDDSURFACEDESC pddsdPrimary; - - /* Privates used by shadow fb DirectDraw Nonlocking server */ - LPDIRECTDRAW4 pdd4; - LPDIRECTDRAWSURFACE4 pddsShadow4; - LPDIRECTDRAWSURFACE4 pddsPrimary4; - BOOL fRetryCreateSurface; - - /* Privates used by both shadow fb DirectDraw servers */ - LPDIRECTDRAWCLIPPER pddcPrimary; - -#ifdef XWIN_MULTIWINDOWEXTWM - /* Privates used by multi-window external window manager */ - RootlessFrameID widTop; - Bool fRestacking; -#endif - -#ifdef XWIN_MULTIWINDOW - /* Privates used by multi-window */ - pthread_t ptWMProc; - pthread_t ptXMsgProc; - void *pWMInfo; -#endif - -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - /* Privates used by both multi-window and rootless */ - Bool fRootWindowShown; -#endif - -#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) - /* Privates used for any module running in a seperate thread */ - pthread_mutex_t pmServerStarted; - Bool fServerStarted; -#endif - - /* Engine specific functions */ - winAllocateFBProcPtr pwinAllocateFB; - winShadowUpdateProcPtr pwinShadowUpdate; - winCloseScreenProcPtr pwinCloseScreen; - winInitVisualsProcPtr pwinInitVisuals; - winAdjustVideoModeProcPtr pwinAdjustVideoMode; - winCreateBoundingWindowProcPtr pwinCreateBoundingWindow; - winFinishScreenInitProcPtr pwinFinishScreenInit; - winBltExposedRegionsProcPtr pwinBltExposedRegions; - winActivateAppProcPtr pwinActivateApp; - winRedrawScreenProcPtr pwinRedrawScreen; - winRealizeInstalledPaletteProcPtr pwinRealizeInstalledPalette; - winInstallColormapProcPtr pwinInstallColormap; - winStoreColorsProcPtr pwinStoreColors; - winCreateColormapProcPtr pwinCreateColormap; - winDestroyColormapProcPtr pwinDestroyColormap; - winHotKeyAltTabProcPtr pwinHotKeyAltTab; - winCreatePrimarySurfaceProcPtr pwinCreatePrimarySurface; - winReleasePrimarySurfaceProcPtr pwinReleasePrimarySurface; - - winCreateScreenResourcesProc pwinCreateScreenResources; - -#ifdef XWIN_MULTIWINDOW - /* Window Procedures for MultiWindow mode */ - winFinishCreateWindowsWindowProcPtr pwinFinishCreateWindowsWindow; -#endif - - /* Window Procedures for Rootless mode */ - CreateWindowProcPtr CreateWindow; - DestroyWindowProcPtr DestroyWindow; - PositionWindowProcPtr PositionWindow; - ChangeWindowAttributesProcPtr ChangeWindowAttributes; - RealizeWindowProcPtr RealizeWindow; - UnrealizeWindowProcPtr UnrealizeWindow; - ValidateTreeProcPtr ValidateTree; - PostValidateTreeProcPtr PostValidateTree; - WindowExposuresProcPtr WindowExposures; - CopyWindowProcPtr CopyWindow; - ClearToBackgroundProcPtr ClearToBackground; - ClipNotifyProcPtr ClipNotify; - RestackWindowProcPtr RestackWindow; - ReparentWindowProcPtr ReparentWindow; - ResizeWindowProcPtr ResizeWindow; - MoveWindowProcPtr MoveWindow; - SetShapeProcPtr SetShape; - -#ifdef XWIN_NATIVEGDI - RealizeFontProcPtr RealizeFont; - UnrealizeFontProcPtr UnrealizeFont; -#endif - - winCursorRec cursor; -} winPrivScreenRec; - - -#ifdef XWIN_MULTIWINDOWEXTWM -typedef struct { - RootlessWindowPtr pFrame; - HWND hWnd; - int dwWidthBytes; - BITMAPINFOHEADER *pbmihShadow; - HBITMAP hbmpShadow; - HDC hdcShadow; - HDC hdcScreen; - BOOL fResized; - BOOL fRestackingNow; - BOOL fClose; - BOOL fMovingOrSizing; - BOOL fDestroyed;//for debug - char *pfb; -} win32RootlessWindowRec, *win32RootlessWindowPtr; -#endif - - -typedef struct { - pointer value; - XID id; -} WindowIDPairRec, *WindowIDPairPtr; - - -/* - * Extern declares for general global variables - */ - -extern winScreenInfo g_ScreenInfo[]; -extern miPointerScreenFuncRec g_winPointerCursorFuncs; -extern DWORD g_dwEvents; -#ifdef HAS_DEVWINDOWS -extern int g_fdMessageQueue; -#endif -extern DevPrivateKey g_iScreenPrivateKey; -extern DevPrivateKey g_iCmapPrivateKey; -extern DevPrivateKey g_iGCPrivateKey; -extern DevPrivateKey g_iPixmapPrivateKey; -extern DevPrivateKey g_iWindowPrivateKey; -extern unsigned long g_ulServerGeneration; -extern DWORD g_dwEnginesSupported; -extern HINSTANCE g_hInstance; -extern int g_copyROP[]; -extern int g_patternROP[]; -extern const char * g_pszQueryHost; -extern DeviceIntPtr g_pwinPointer; -extern DeviceIntPtr g_pwinKeyboard; - - -/* - * Extern declares for dynamically loaded libraries and function pointers - */ - -extern HMODULE g_hmodDirectDraw; -extern FARPROC g_fpDirectDrawCreate; -extern FARPROC g_fpDirectDrawCreateClipper; - -extern HMODULE g_hmodCommonControls; -extern FARPROC g_fpTrackMouseEvent; - - -/* - * Screen privates macros - */ - -#define winGetScreenPriv(pScreen) ((winPrivScreenPtr) \ - dixLookupPrivate(&(pScreen)->devPrivates, g_iScreenPrivateKey)) - -#define winSetScreenPriv(pScreen,v) \ - dixSetPrivate(&(pScreen)->devPrivates, g_iScreenPrivateKey, v) - -#define winScreenPriv(pScreen) \ - winPrivScreenPtr pScreenPriv = winGetScreenPriv(pScreen) - - -/* - * Colormap privates macros - */ - -#define winGetCmapPriv(pCmap) ((winPrivCmapPtr) \ - dixLookupPrivate(&(pCmap)->devPrivates, g_iCmapPrivateKey)) - -#define winSetCmapPriv(pCmap,v) \ - dixSetPrivate(&(pCmap)->devPrivates, g_iCmapPrivateKey, v) - -#define winCmapPriv(pCmap) \ - winPrivCmapPtr pCmapPriv = winGetCmapPriv(pCmap) - - -/* - * GC privates macros - */ - -#define winGetGCPriv(pGC) ((winPrivGCPtr) \ - dixLookupPrivate(&(pGC)->devPrivates, g_iGCPrivateKey)) - -#define winSetGCPriv(pGC,v) \ - dixSetPrivate(&(pGC)->devPrivates, g_iGCPrivateKey, v) - -#define winGCPriv(pGC) \ - winPrivGCPtr pGCPriv = winGetGCPriv(pGC) - - -/* - * Pixmap privates macros - */ - -#define winGetPixmapPriv(pPixmap) ((winPrivPixmapPtr) \ - dixLookupPrivate(&(pPixmap)->devPrivates, g_iPixmapPrivateKey)) - -#define winSetPixmapPriv(pPixmap,v) \ - dixLookupPrivate(&(pPixmap)->devPrivates, g_iPixmapPrivateKey, v) - -#define winPixmapPriv(pPixmap) \ - winPrivPixmapPtr pPixmapPriv = winGetPixmapPriv(pPixmap) - - -/* - * Window privates macros - */ - -#define winGetWindowPriv(pWin) ((winPrivWinPtr) \ - dixLookupPrivate(&(pWin)->devPrivates, g_iWindowPrivateKey)) - -#define winSetWindowPriv(pWin,v) \ - dixLookupPrivate(&(pWin)->devPrivates, g_iWindowPrivateKey, v) - -#define winWindowPriv(pWin) \ - winPrivWinPtr pWinPriv = winGetWindowPriv(pWin) - -/* - * wrapper macros - */ -#define _WIN_WRAP(priv, real, mem, func) {\ - priv->mem = real->mem; \ - real->mem = func; \ -} - -#define _WIN_UNWRAP(priv, real, mem) {\ - real->mem = priv->mem; \ -} - -#define WIN_WRAP(mem, func) _WIN_WRAP(pScreenPriv, pScreen, mem, func) - -#define WIN_UNWRAP(mem) _WIN_UNWRAP(pScreenPriv, pScreen, mem) - -/* - * BEGIN DDX and DIX Function Prototypes - */ - - -/* - * winallpriv.c - */ - -Bool -winAllocatePrivates (ScreenPtr pScreen); - -Bool -winInitCmapPrivates (ColormapPtr pCmap, int index); - -Bool -winAllocateCmapPrivates (ColormapPtr pCmap); - - -/* - * winauth.c - */ - -#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) -# if defined(XCSECURITY) -Bool -winGenerateAuthorization (void); -# endif -#endif - - -/* - * winblock.c - */ - -void -winBlockHandler (int nScreen, - pointer pBlockData, - pointer pTimeout, - pointer pReadMask); - - -#ifdef XWIN_NATIVEGDI -/* - * winclip.c - */ - -RegionPtr -winPixmapToRegionNativeGDI (PixmapPtr pPix); -#endif - - -#ifdef XWIN_CLIPBOARD -/* - * winclipboardinit.c - */ - -Bool -winInitClipboard (void); - -void -winFixClipboardChain (void); -#endif - - -/* - * wincmap.c - */ - -void -winSetColormapFunctions (ScreenPtr pScreen); - -Bool -winCreateDefColormap (ScreenPtr pScreen); - - -/* - * wincreatewnd.c - */ - -Bool -winCreateBoundingWindowFullScreen (ScreenPtr pScreen); - -Bool -winCreateBoundingWindowWindowed (ScreenPtr pScreen); - - -/* - * windialogs.c - */ - -int -GetLiveClients (winPrivScreenPtr pScreenPriv); - -void -winDisplayExitDialog (winPrivScreenPtr pScreenPriv); - -void -winDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv); - -void -winDisplayAboutDialog (winPrivScreenPtr pScreenPriv); - - -/* - * winengine.c - */ - -void -winDetectSupportedEngines (void); - -Bool -winSetEngine (ScreenPtr pScreen); - -Bool -winGetDDProcAddresses (void); - - -/* - * winerror.c - */ - -#ifdef DDXOSVERRORF -void -OSVenderVErrorF (const char *pszFormat, va_list va_args); -#endif - -void -winMessageBoxF (const char *pszError, UINT uType, ...); - - -#ifdef XWIN_NATIVEGDI -/* - * winfillsp.c - */ - -void -winFillSpansNativeGDI (DrawablePtr pDrawable, - GCPtr pGC, - int nSpans, - DDXPointPtr pPoints, - int *pWidths, - int fSorted); -#endif - - -#ifdef XWIN_NATIVEGDI -/* - * winfont.c - */ - -Bool -winRealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont); - -Bool -winUnrealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont); -#endif - - -#ifdef XWIN_NATIVEGDI -/* - * wingc.c - */ - -Bool -winCreateGCNativeGDI (GCPtr pGC); -#endif - - -#ifdef XWIN_NATIVEGDI -/* - * wingetsp.c - */ - -void -winGetSpansNativeGDI (DrawablePtr pDrawable, - int wMax, - DDXPointPtr pPoints, - int *pWidths, - int nSpans, - char *pDst); -#endif - - -/* - * winglobals.c - */ - -void -winInitializeGlobals (void); - - -/* - * winkeybd.c - */ - -void -winTranslateKey (WPARAM wParam, LPARAM lParam, int *piScanCode); - -int -winKeybdProc (DeviceIntPtr pDeviceInt, int iState); - -void -winInitializeModeKeyStates (void); - -void -winRestoreModeKeyStates (void); - -Bool -winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam); - -void -winKeybdReleaseKeys (void); - -void -winSendKeyEvent (DWORD dwKey, Bool fDown); - -BOOL -winCheckKeyPressed(WPARAM wParam, LPARAM lParam); - -void -winFixShiftKeys (int iScanCode); - -/* - * winkeyhook.c - */ - -Bool -winInstallKeyboardHookLL (void); - -void -winRemoveKeyboardHookLL (void); - - -/* - * winmisc.c - */ - -#ifdef XWIN_NATIVEGDI -void -winQueryBestSizeNativeGDI (int class, unsigned short *pWidth, - unsigned short *pHeight, ScreenPtr pScreen); -#endif - -CARD8 -winCountBits (DWORD dw); - -Bool -winUpdateFBPointer (ScreenPtr pScreen, void *pbits); - -#ifdef XWIN_NATIVEGDI -BOOL -winPaintBackground (HWND hwnd, COLORREF colorref); -#endif - - -/* - * winmouse.c - */ - -int -winMouseProc (DeviceIntPtr pDeviceInt, int iState); - -int -winMouseWheel (ScreenPtr pScreen, int iDeltaZ); - -void -winMouseButtonsSendEvent (int iEventType, int iButton); - -int -winMouseButtonsHandle (ScreenPtr pScreen, - int iEventType, int iButton, - WPARAM wParam); - -void -winEnqueueMotion(int x, int y); - -#ifdef XWIN_NATIVEGDI -/* - * winnativegdi.c - */ - -HBITMAP -winCreateDIBNativeGDI (int iWidth, int iHeight, int iDepth, - BYTE **ppbBits, BITMAPINFO **ppbmi); - -Bool -winSetEngineFunctionsNativeGDI (ScreenPtr pScreen); -#endif - - -#ifdef XWIN_PRIMARYFB -/* - * winpfbddd.c - */ - -Bool -winSetEngineFunctionsPrimaryDD (ScreenPtr pScreen); -#endif - - -#ifdef XWIN_NATIVEGDI -/* - * winpixmap.c - */ - -PixmapPtr -winCreatePixmapNativeGDI (ScreenPtr pScreen, int width, int height, int depth, - unsigned usage_hint); - -Bool -winDestroyPixmapNativeGDI (PixmapPtr pPixmap); - -Bool -winModifyPixmapHeaderNativeGDI (PixmapPtr pPixmap, - int iWidth, int iHeight, - int iDepth, - int iBitsPerPixel, - int devKind, - pointer pPixData); -#endif - -#ifdef XWIN_NATIVEGDI -/* - * winpolyline.c - */ - -void -winPolyLineNativeGDI (DrawablePtr pDrawable, - GCPtr pGC, - int mode, - int npt, - DDXPointPtr ppt); -#endif - - -#ifdef XWIN_NATIVEGDI -/* - * winpushpxl.c - */ - -void -winPushPixels (GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable, - int dx, int dy, int xOrg, int yOrg); -#endif - - -/* - * winscrinit.c - */ - -Bool -winScreenInit (int index, - ScreenPtr pScreen, - int argc, char **argv); - -Bool -winFinishScreenInitFB (int index, - ScreenPtr pScreen, - int argc, char **argv); - -#if defined(XWIN_NATIVEGDI) -Bool -winFinishScreenInitNativeGDI (int index, - ScreenPtr pScreen, - int argc, char **argv); -#endif - - -#ifdef XWIN_NATIVEGDI -/* - * winsetsp.c - */ - -void -winSetSpansNativeGDI (DrawablePtr pDrawable, - GCPtr pGC, - char *pSrc, - DDXPointPtr pPoints, - int *pWidth, - int nSpans, - int fSorted); -#endif - - -/* - * winshaddd.c - */ - -Bool -winSetEngineFunctionsShadowDD (ScreenPtr pScreen); - - -/* - * winshadddnl.c - */ - -Bool -winSetEngineFunctionsShadowDDNL (ScreenPtr pScreen); - - -/* - * winshadgdi.c - */ - -Bool -winSetEngineFunctionsShadowGDI (ScreenPtr pScreen); - - -/* - * winwakeup.c - */ - -void -winWakeupHandler (int nScreen, - pointer pWakeupData, - unsigned long ulResult, - pointer pReadmask); - - -/* - * winwindow.c - */ - -#ifdef XWIN_NATIVEGDI -Bool -winCreateWindowNativeGDI (WindowPtr pWin); - -Bool -winDestroyWindowNativeGDI (WindowPtr pWin); - -Bool -winPositionWindowNativeGDI (WindowPtr pWin, int x, int y); - -void -winCopyWindowNativeGDI (WindowPtr pWin, - DDXPointRec ptOldOrg, - RegionPtr prgnSrc); - -Bool -winChangeWindowAttributesNativeGDI (WindowPtr pWin, unsigned long mask); - -Bool -winUnmapWindowNativeGDI (WindowPtr pWindow); - -Bool -winMapWindowNativeGDI (WindowPtr pWindow); -#endif - -Bool -winCreateWindowRootless (WindowPtr pWindow); - -Bool -winDestroyWindowRootless (WindowPtr pWindow); - -Bool -winPositionWindowRootless (WindowPtr pWindow, int x, int y); - -Bool -winChangeWindowAttributesRootless (WindowPtr pWindow, unsigned long mask); - -Bool -winUnmapWindowRootless (WindowPtr pWindow); - -Bool -winMapWindowRootless (WindowPtr pWindow); - -void -winSetShapeRootless (WindowPtr pWindow); - - -/* - * winmultiwindowicons.c - Used by both multi-window and Win32Rootless - */ - -HICON -winXIconToHICON (WindowPtr pWin, int iconSize); - -void -winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon); - -#ifdef XWIN_MULTIWINDOW -/* - * winmultiwindowshape.c - */ - -void -winReshapeMultiWindow (WindowPtr pWin); - -void -winSetShapeMultiWindow (WindowPtr pWindow); - -void -winUpdateRgnMultiWindow (WindowPtr pWindow); -#endif - - -#ifdef XWIN_MULTIWINDOW -/* - * winmultiwindowwindow.c - */ - -Bool -winCreateWindowMultiWindow (WindowPtr pWindow); - -Bool -winDestroyWindowMultiWindow (WindowPtr pWindow); - -Bool -winPositionWindowMultiWindow (WindowPtr pWindow, int x, int y); - -Bool -winChangeWindowAttributesMultiWindow (WindowPtr pWindow, unsigned long mask); - -Bool -winUnmapWindowMultiWindow (WindowPtr pWindow); - -Bool -winMapWindowMultiWindow (WindowPtr pWindow); - -void -winReparentWindowMultiWindow (WindowPtr pWin, WindowPtr pPriorParent); - -void -winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib); - -void -winReorderWindowsMultiWindow (void); - -void -winResizeWindowMultiWindow (WindowPtr pWin, int x, int y, unsigned int w, - unsigned int h, WindowPtr pSib); -void -winMoveWindowMultiWindow (WindowPtr pWin, int x, int y, - WindowPtr pSib, VTKind kind); - -void -winCopyWindowMultiWindow (WindowPtr pWin, DDXPointRec oldpt, - RegionPtr oldRegion); - -XID -winGetWindowID (WindowPtr pWin); - -int -winAdjustXWindow (WindowPtr pWin, HWND hwnd); -#endif - - -#ifdef XWIN_MULTIWINDOW -/* - * winmultiwindowwndproc.c - */ - -LRESULT CALLBACK -winTopLevelWindowProc (HWND hwnd, UINT message, - WPARAM wParam, LPARAM lParam); -#endif - - -/* - * wintrayicon.c - */ - -void -winInitNotifyIcon (winPrivScreenPtr pScreenPriv, Bool Modify); - -void -winDeleteNotifyIcon (winPrivScreenPtr pScreenPriv); - -LRESULT -winHandleIconMessage (HWND hwnd, UINT message, - WPARAM wParam, LPARAM lParam, - winPrivScreenPtr pScreenPriv); - - -/* - * winwndproc.c - */ - -LRESULT CALLBACK -winWindowProc (HWND hWnd, UINT message, - WPARAM wParam, LPARAM lParam); - - -#ifdef XWIN_MULTIWINDOWEXTWM -/* - * winwin32rootless.c - */ - -Bool -winMWExtWMCreateFrame (RootlessWindowPtr pFrame, ScreenPtr pScreen, - int newX, int newY, RegionPtr pShape); - -void -winMWExtWMDestroyFrame (RootlessFrameID wid); - -void -winMWExtWMMoveFrame (RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY); - -void -winMWExtWMResizeFrame (RootlessFrameID wid, ScreenPtr pScreen, - int newX, int newY, unsigned int newW, unsigned int newH, - unsigned int gravity); - -void -winMWExtWMRestackFrame (RootlessFrameID wid, RootlessFrameID nextWid); - -void -winMWExtWMReshapeFrame (RootlessFrameID wid, RegionPtr pShape); - -void -winMWExtWMUnmapFrame (RootlessFrameID wid); - -void -winMWExtWMStartDrawing (RootlessFrameID wid, char **pixelData, int *bytesPerRow); - -void -winMWExtWMStopDrawing (RootlessFrameID wid, Bool flush); - -void -winMWExtWMUpdateRegion (RootlessFrameID wid, RegionPtr pDamage); - -void -winMWExtWMDamageRects (RootlessFrameID wid, int count, const BoxRec *rects, - int shift_x, int shift_y); - -void -winMWExtWMRootlessSwitchWindow (RootlessWindowPtr pFrame, WindowPtr oldWin); - -void -winMWExtWMCopyBytes (unsigned int width, unsigned int height, - const void *src, unsigned int srcRowBytes, - void *dst, unsigned int dstRowBytes); - -void -winMWExtWMFillBytes (unsigned int width, unsigned int height, unsigned int value, - void *dst, unsigned int dstRowBytes); - -int -winMWExtWMCompositePixels (unsigned int width, unsigned int height, unsigned int function, - void *src[2], unsigned int srcRowBytes[2], - void *mask, unsigned int maskRowBytes, - void *dst[2], unsigned int dstRowBytes[2]); - -void -winMWExtWMCopyWindow (RootlessFrameID wid, int dstNrects, const BoxRec *dstRects, - int dx, int dy); -#endif - - -#ifdef XWIN_MULTIWINDOWEXTWM -/* - * winwin32rootlesswindow.c - */ - -void -winMWExtWMReorderWindows (ScreenPtr pScreen); - -void -winMWExtWMMoveXWindow (WindowPtr pWin, int x, int y); - -void -winMWExtWMResizeXWindow (WindowPtr pWin, int w, int h); - -void -winMWExtWMMoveResizeXWindow (WindowPtr pWin, int x, int y, int w, int h); - -void -winMWExtWMUpdateIcon (Window id); - -void -winMWExtWMUpdateWindowDecoration (win32RootlessWindowPtr pRLWinPriv, - winScreenInfoPtr pScreenInfo); - -wBOOL CALLBACK -winMWExtWMDecorateWindow (HWND hwnd, LPARAM lParam); - -Bool -winIsInternalWMRunning (winScreenInfoPtr pScreenInfo); - -void -winMWExtWMRestackWindows (ScreenPtr pScreen); -#endif - - -#ifdef XWIN_MULTIWINDOWEXTWM -/* - * winwin32rootlesswndproc.c - */ - -LRESULT CALLBACK -winMWExtWMWindowProc (HWND hwnd, UINT message, - WPARAM wParam, LPARAM lParam); -#endif - - -/* - * winwindowswm.c - */ - -void -winWindowsWMSendEvent (int type, unsigned int mask, int which, int arg, - Window window, int x, int y, int w, int h); - -void -winWindowsWMExtensionInit (void); - -/* - * wincursor.c - */ - -Bool -winInitCursor (ScreenPtr pScreen); - -/* - * END DDX and DIX Function Prototypes - */ - -#endif /* _WIN_H_ */ - +/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Dakshinamurthy Karra
+ * Suhaib M Siddiqi
+ * Peter Busch
+ * Harold L Hunt II
+ * Kensuke Matsuzaki
+ */
+
+#ifndef _WIN_H_
+#define _WIN_H_
+
+#ifndef NO
+#define NO 0
+#endif
+#ifndef YES
+#define YES 1
+#endif
+
+/* WM_XBUTTON Messages. They should go into w32api. */
+#ifndef WM_XBUTTONDOWN
+# define WM_XBUTTONDOWN 523
+#endif
+#ifndef WM_XBUTTONUP
+# define WM_XBUTTONUP 524
+#endif
+#ifndef WM_XBUTTONDBLCLK
+# define WM_XBUTTONDBLCLK 525
+#endif
+
+
+#define WIN_DEFAULT_BPP 0
+#define WIN_DEFAULT_WHITEPIXEL 255
+#define WIN_DEFAULT_BLACKPIXEL 0
+#define WIN_DEFAULT_LINEBIAS 0
+#define WIN_DEFAULT_E3B_TIME 50 /* milliseconds */
+#define WIN_DEFAULT_DPI 75
+#define WIN_DEFAULT_REFRESH 0
+#define WIN_DEFAULT_WIN_KILL TRUE
+#define WIN_DEFAULT_UNIX_KILL FALSE
+#define WIN_DEFAULT_CLIP_UPDATES_NBOXES 0
+#ifdef XWIN_EMULATEPSEUDO
+#define WIN_DEFAULT_EMULATE_PSEUDO FALSE
+#endif
+#define WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH FALSE
+
+#define WIN_DIB_MAXIMUM_SIZE 0x08000000 /* 16 MB on Windows 95, 98, Me */
+#define WIN_DIB_MAXIMUM_SIZE_MB (WIN_DIB_MAXIMUM_SIZE / 8 / 1024 / 1024)
+
+/*
+ * Windows only supports 256 color palettes
+ */
+#define WIN_NUM_PALETTE_ENTRIES 256
+
+/*
+ * Number of times to call Restore in an attempt to restore the primary surface
+ */
+#define WIN_REGAIN_SURFACE_RETRIES 1
+
+/*
+ * Build a supported display depths mask by shifting one to the left
+ * by the number of bits in the supported depth.
+ */
+#define WIN_SUPPORTED_BPPS ( (1 << (32 - 1)) | (1 << (24 - 1)) \
+ | (1 << (16 - 1)) | (1 << (15 - 1)) \
+ | (1 << ( 8 - 1)))
+#define WIN_CHECK_DEPTH YES
+
+/*
+ * Timer IDs for WM_TIMER
+ */
+#define WIN_E3B_TIMER_ID 1
+#define WIN_POLLING_MOUSE_TIMER_ID 2
+
+#define MOUSE_POLLING_INTERVAL 50
+
+#define WIN_E3B_OFF -1
+#define WIN_FD_INVALID -1
+
+#define WIN_SERVER_NONE 0x0L /* 0 */
+#define WIN_SERVER_SHADOW_GDI 0x1L /* 1 */
+#define WIN_SERVER_SHADOW_DD 0x2L /* 2 */
+#define WIN_SERVER_SHADOW_DDNL 0x4L /* 4 */
+#ifdef XWIN_PRIMARYFB
+#define WIN_SERVER_PRIMARY_DD 0x8L /* 8 */
+#endif
+#ifdef XWIN_NATIVEGDI
+# define WIN_SERVER_NATIVE_GDI 0x10L /* 16 */
+#endif
+
+#define AltMapIndex Mod1MapIndex
+#define NumLockMapIndex Mod2MapIndex
+#define AltLangMapIndex Mod3MapIndex
+#define KanaMapIndex Mod4MapIndex
+#define ScrollLockMapIndex Mod5MapIndex
+
+#define WIN_MOD_LALT 0x00000001
+#define WIN_MOD_RALT 0x00000002
+#define WIN_MOD_LCONTROL 0x00000004
+#define WIN_MOD_RCONTROL 0x00000008
+
+#define WIN_24BPP_MASK_RED 0x00FF0000
+#define WIN_24BPP_MASK_GREEN 0x0000FF00
+#define WIN_24BPP_MASK_BLUE 0x000000FF
+
+#define WIN_MAX_KEYS_PER_KEY 4
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+
+#include <errno.h>
+#if defined(XWIN_MULTIWINDOWEXTWM) || defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+#define HANDLE void *
+#ifdef _MSC_VER
+typedef int pid_t;
+#endif
+#include <pthread.h>
+#undef HANDLE
+#endif
+
+#ifdef HAS_MMAP
+#include <sys/mman.h>
+#ifndef MAP_FILE
+#define MAP_FILE 0
+#endif /* MAP_FILE */
+#endif /* HAS_MMAP */
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include <X11/Xos.h>
+#include <X11/Xprotostr.h>
+#include "scrnintstr.h"
+#include "pixmapstr.h"
+#include "pixmap.h"
+#include "region.h"
+#include "gcstruct.h"
+#include "colormap.h"
+#include "colormapst.h"
+#include "miscstruct.h"
+#include "servermd.h"
+#include "windowstr.h"
+#include "mi.h"
+#include "micmap.h"
+#include "mifillarc.h"
+#include "mifpoly.h"
+#include "mibstore.h"
+#include "input.h"
+#include "mipointer.h"
+#include "X11/keysym.h"
+#include "mibstore.h"
+#include "micoord.h"
+#include "dix.h"
+#include "miline.h"
+#include "shadow.h"
+#include "fb.h"
+#include "rootless.h"
+
+#ifdef RENDER
+#include "mipict.h"
+#include "picturestr.h"
+#endif
+
+#ifdef RANDR
+#include "randrstr.h"
+#endif
+
+/*
+ * Windows headers
+ */
+#include "winms.h"
+#include "./winresource.h"
+
+
+/*
+ * Define Windows constants
+ */
+
+#define WM_TRAYICON (WM_USER + 1000)
+#define WM_INIT_SYS_MENU (WM_USER + 1001)
+#define WM_GIVEUP (WM_USER + 1002)
+
+
+/* Local includes */
+#include "winwindow.h"
+#include "winmsg.h"
+
+#define PROFILEPOINT(point,thresh)\
+{\
+static unsigned int PROFPT##point = 0;\
+if (++PROFPT##point % thresh == 0)\
+ErrorF (#point ": PROFILEPOINT hit %u times\n", PROFPT##point);\
+}
+
+
+/* We use xor this macro for detecting toggle key state changes */
+#define WIN_XOR(a,b) ((!(a) && (b)) || ((a) && !(b)))
+
+#define DEFINE_ATOM_HELPER(func,atom_name) \
+static Atom func (void) { \
+ static int generation; \
+ static Atom atom; \
+ if (generation != serverGeneration) { \
+ generation = serverGeneration; \
+ atom = MakeAtom (atom_name, strlen (atom_name), TRUE); \
+ } \
+ return atom; \
+}
+
+/*
+ * Typedefs for engine dependent function pointers
+ */
+
+typedef Bool (*winAllocateFBProcPtr)(ScreenPtr);
+
+typedef void (*winShadowUpdateProcPtr)(ScreenPtr, shadowBufPtr);
+
+typedef Bool (*winCloseScreenProcPtr)(int, ScreenPtr);
+
+typedef Bool (*winInitVisualsProcPtr)(ScreenPtr);
+
+typedef Bool (*winAdjustVideoModeProcPtr)(ScreenPtr);
+
+typedef Bool (*winCreateBoundingWindowProcPtr)(ScreenPtr);
+
+typedef Bool (*winFinishScreenInitProcPtr)(int, ScreenPtr, int, char **);
+
+typedef Bool (*winBltExposedRegionsProcPtr)(ScreenPtr);
+
+typedef Bool (*winActivateAppProcPtr)(ScreenPtr);
+
+typedef Bool (*winRedrawScreenProcPtr)(ScreenPtr pScreen);
+
+typedef Bool (*winRealizeInstalledPaletteProcPtr)(ScreenPtr pScreen);
+
+typedef Bool (*winInstallColormapProcPtr)(ColormapPtr pColormap);
+
+typedef Bool (*winStoreColorsProcPtr)(ColormapPtr pmap,
+ int ndef, xColorItem *pdefs);
+
+typedef Bool (*winCreateColormapProcPtr)(ColormapPtr pColormap);
+
+typedef Bool (*winDestroyColormapProcPtr)(ColormapPtr pColormap);
+
+typedef Bool (*winHotKeyAltTabProcPtr)(ScreenPtr);
+
+typedef Bool (*winCreatePrimarySurfaceProcPtr)(ScreenPtr);
+
+typedef Bool (*winReleasePrimarySurfaceProcPtr)(ScreenPtr);
+
+typedef Bool (*winFinishCreateWindowsWindowProcPtr)(WindowPtr pWin);
+
+typedef Bool (*winCreateScreenResourcesProc)(ScreenPtr);
+
+/* Typedef for DIX wrapper functions */
+typedef int (*winDispatchProcPtr) (ClientPtr);
+
+
+/*
+ * GC (graphics context) privates
+ */
+
+typedef struct
+{
+ HDC hdc;
+ HDC hdcMem;
+} winPrivGCRec, *winPrivGCPtr;
+
+
+/*
+ * Pixmap privates
+ */
+
+typedef struct
+{
+ HDC hdcSelected;
+ HBITMAP hBitmap;
+ BYTE *pbBits;
+ DWORD dwScanlineBytes;
+ BITMAPINFOHEADER *pbmih;
+} winPrivPixmapRec, *winPrivPixmapPtr;
+
+
+/*
+ * Colormap privates
+ */
+
+typedef struct
+{
+ HPALETTE hPalette;
+ LPDIRECTDRAWPALETTE lpDDPalette;
+ RGBQUAD rgbColors[WIN_NUM_PALETTE_ENTRIES];
+ PALETTEENTRY peColors[WIN_NUM_PALETTE_ENTRIES];
+} winPrivCmapRec, *winPrivCmapPtr;
+
+/*
+ * Windows Cursor handling.
+ */
+
+typedef struct {
+ /* from GetSystemMetrics */
+ int sm_cx;
+ int sm_cy;
+
+ BOOL visible;
+ HCURSOR handle;
+ QueryBestSizeProcPtr QueryBestSize;
+ miPointerSpriteFuncPtr spriteFuncs;
+} winCursorRec;
+
+/*
+ * Screen information structure that we need before privates are available
+ * in the server startup sequence.
+ */
+
+typedef struct
+{
+ ScreenPtr pScreen;
+
+ /* Did the user specify a height and width? */
+ Bool fUserGaveHeightAndWidth;
+
+ DWORD dwScreen;
+ DWORD dwUserWidth;
+ DWORD dwUserHeight;
+ DWORD dwWidth;
+ DWORD dwHeight;
+ DWORD dwWidth_mm;
+ DWORD dwHeight_mm;
+ DWORD dwPaddedWidth;
+
+ /* Did the user specify a screen position? */
+ Bool fUserGavePosition;
+ DWORD dwInitialX;
+ DWORD dwInitialY;
+
+ /*
+ * dwStride is the number of whole pixels that occupy a scanline,
+ * including those pixels that are not displayed. This is basically
+ * a rounding up of the width.
+ */
+ DWORD dwStride;
+
+ /* Offset of the screen in the window when using scrollbars */
+ DWORD dwXOffset;
+ DWORD dwYOffset;
+
+ DWORD dwBPP;
+ DWORD dwDepth;
+ DWORD dwRefreshRate;
+ char *pfb;
+ DWORD dwEngine;
+ DWORD dwEnginePreferred;
+ DWORD dwClipUpdatesNBoxes;
+#ifdef XWIN_EMULATEPSEUDO
+ Bool fEmulatePseudo;
+#endif
+ Bool fFullScreen;
+ Bool fDecoration;
+#ifdef XWIN_MULTIWINDOWEXTWM
+ Bool fMWExtWM;
+ Bool fInternalWM;
+ Bool fAnotherWMRunning;
+#endif
+ Bool fRootless;
+#ifdef XWIN_MULTIWINDOW
+ Bool fMultiWindow;
+#endif
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ Bool fMultiMonitorOverride;
+#endif
+ Bool fMultipleMonitors;
+ Bool fLessPointer;
+ Bool fScrollbars;
+ Bool fNoTrayIcon;
+ int iE3BTimeout;
+ /* Windows (Alt+F4) and Unix (Ctrl+Alt+Backspace) Killkey */
+ Bool fUseWinKillKey;
+ Bool fUseUnixKillKey;
+ Bool fIgnoreInput;
+
+ /* Did the user explicitly set this screen? */
+ Bool fExplicitScreen;
+} winScreenInfo, *winScreenInfoPtr;
+
+
+/*
+ * Screen privates
+ */
+
+typedef struct _winPrivScreenRec
+{
+ winScreenInfoPtr pScreenInfo;
+
+ Bool fEnabled;
+ Bool fClosed;
+ Bool fActive;
+ Bool fBadDepth;
+
+ int iDeltaZ;
+
+ int iConnectedClients;
+
+ CloseScreenProcPtr CloseScreen;
+
+ DWORD dwRedMask;
+ DWORD dwGreenMask;
+ DWORD dwBlueMask;
+ DWORD dwBitsPerRGB;
+
+ DWORD dwModeKeyStates;
+
+ /* Handle to icons that must be freed */
+ HICON hiconNotifyIcon;
+
+ /* Last width, height, and depth of the Windows display */
+ DWORD dwLastWindowsWidth;
+ DWORD dwLastWindowsHeight;
+ DWORD dwLastWindowsBitsPixel;
+
+ /* Palette management */
+ ColormapPtr pcmapInstalled;
+
+ /* Pointer to the root visual so we only have to look it up once */
+ VisualPtr pRootVisual;
+
+ /* 3 button emulation variables */
+ int iE3BCachedPress;
+ Bool fE3BFakeButton2Sent;
+
+ /* Privates used by shadow fb GDI server */
+ HBITMAP hbmpShadow;
+ HDC hdcScreen;
+ HDC hdcShadow;
+ HWND hwndScreen;
+
+ /* Privates used by shadow fb and primary fb DirectDraw servers */
+ LPDIRECTDRAW pdd;
+ LPDIRECTDRAWSURFACE2 pddsPrimary;
+ LPDIRECTDRAW2 pdd2;
+
+ /* Privates used by shadow fb DirectDraw server */
+ LPDIRECTDRAWSURFACE2 pddsShadow;
+ LPDDSURFACEDESC pddsdShadow;
+
+ /* Privates used by primary fb DirectDraw server */
+ LPDIRECTDRAWSURFACE2 pddsOffscreen;
+ LPDDSURFACEDESC pddsdOffscreen;
+ LPDDSURFACEDESC pddsdPrimary;
+
+ /* Privates used by shadow fb DirectDraw Nonlocking server */
+ LPDIRECTDRAW4 pdd4;
+ LPDIRECTDRAWSURFACE4 pddsShadow4;
+ LPDIRECTDRAWSURFACE4 pddsPrimary4;
+ BOOL fRetryCreateSurface;
+
+ /* Privates used by both shadow fb DirectDraw servers */
+ LPDIRECTDRAWCLIPPER pddcPrimary;
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+ /* Privates used by multi-window external window manager */
+ RootlessFrameID widTop;
+ Bool fRestacking;
+#endif
+
+#ifdef XWIN_MULTIWINDOW
+ /* Privates used by multi-window */
+ pthread_t ptWMProc;
+ pthread_t ptXMsgProc;
+ void *pWMInfo;
+#endif
+
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ /* Privates used by both multi-window and rootless */
+ Bool fRootWindowShown;
+#endif
+
+#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+ /* Privates used for any module running in a seperate thread */
+ pthread_mutex_t pmServerStarted;
+ Bool fServerStarted;
+#endif
+
+ /* Engine specific functions */
+ winAllocateFBProcPtr pwinAllocateFB;
+ winShadowUpdateProcPtr pwinShadowUpdate;
+ winCloseScreenProcPtr pwinCloseScreen;
+ winInitVisualsProcPtr pwinInitVisuals;
+ winAdjustVideoModeProcPtr pwinAdjustVideoMode;
+ winCreateBoundingWindowProcPtr pwinCreateBoundingWindow;
+ winFinishScreenInitProcPtr pwinFinishScreenInit;
+ winBltExposedRegionsProcPtr pwinBltExposedRegions;
+ winActivateAppProcPtr pwinActivateApp;
+ winRedrawScreenProcPtr pwinRedrawScreen;
+ winRealizeInstalledPaletteProcPtr pwinRealizeInstalledPalette;
+ winInstallColormapProcPtr pwinInstallColormap;
+ winStoreColorsProcPtr pwinStoreColors;
+ winCreateColormapProcPtr pwinCreateColormap;
+ winDestroyColormapProcPtr pwinDestroyColormap;
+ winHotKeyAltTabProcPtr pwinHotKeyAltTab;
+ winCreatePrimarySurfaceProcPtr pwinCreatePrimarySurface;
+ winReleasePrimarySurfaceProcPtr pwinReleasePrimarySurface;
+
+ winCreateScreenResourcesProc pwinCreateScreenResources;
+
+#ifdef XWIN_MULTIWINDOW
+ /* Window Procedures for MultiWindow mode */
+ winFinishCreateWindowsWindowProcPtr pwinFinishCreateWindowsWindow;
+#endif
+
+ /* Window Procedures for Rootless mode */
+ CreateWindowProcPtr CreateWindow;
+ DestroyWindowProcPtr DestroyWindow;
+ PositionWindowProcPtr PositionWindow;
+ ChangeWindowAttributesProcPtr ChangeWindowAttributes;
+ RealizeWindowProcPtr RealizeWindow;
+ UnrealizeWindowProcPtr UnrealizeWindow;
+ ValidateTreeProcPtr ValidateTree;
+ PostValidateTreeProcPtr PostValidateTree;
+ WindowExposuresProcPtr WindowExposures;
+ CopyWindowProcPtr CopyWindow;
+ ClearToBackgroundProcPtr ClearToBackground;
+ ClipNotifyProcPtr ClipNotify;
+ RestackWindowProcPtr RestackWindow;
+ ReparentWindowProcPtr ReparentWindow;
+ ResizeWindowProcPtr ResizeWindow;
+ MoveWindowProcPtr MoveWindow;
+ SetShapeProcPtr SetShape;
+
+#ifdef XWIN_NATIVEGDI
+ RealizeFontProcPtr RealizeFont;
+ UnrealizeFontProcPtr UnrealizeFont;
+#endif
+
+ winCursorRec cursor;
+} winPrivScreenRec;
+
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+typedef struct {
+ RootlessWindowPtr pFrame;
+ HWND hWnd;
+ int dwWidthBytes;
+ BITMAPINFOHEADER *pbmihShadow;
+ HBITMAP hbmpShadow;
+ HDC hdcShadow;
+ HDC hdcScreen;
+ BOOL fResized;
+ BOOL fRestackingNow;
+ BOOL fClose;
+ BOOL fMovingOrSizing;
+ BOOL fDestroyed;//for debug
+ char *pfb;
+} win32RootlessWindowRec, *win32RootlessWindowPtr;
+#endif
+
+
+typedef struct {
+ pointer value;
+ XID id;
+} WindowIDPairRec, *WindowIDPairPtr;
+
+
+/*
+ * Extern declares for general global variables
+ */
+
+extern winScreenInfo g_ScreenInfo[];
+extern miPointerScreenFuncRec g_winPointerCursorFuncs;
+extern DWORD g_dwEvents;
+#ifdef HAS_DEVWINDOWS
+extern int g_fdMessageQueue;
+#endif
+extern DevPrivateKey g_iScreenPrivateKey;
+extern DevPrivateKey g_iCmapPrivateKey;
+extern DevPrivateKey g_iGCPrivateKey;
+extern DevPrivateKey g_iPixmapPrivateKey;
+extern DevPrivateKey g_iWindowPrivateKey;
+extern unsigned long g_ulServerGeneration;
+extern DWORD g_dwEnginesSupported;
+extern HINSTANCE g_hInstance;
+extern int g_copyROP[];
+extern int g_patternROP[];
+extern const char * g_pszQueryHost;
+extern DeviceIntPtr g_pwinPointer;
+extern DeviceIntPtr g_pwinKeyboard;
+
+
+/*
+ * Extern declares for dynamically loaded libraries and function pointers
+ */
+
+extern HMODULE g_hmodDirectDraw;
+extern FARPROC g_fpDirectDrawCreate;
+extern FARPROC g_fpDirectDrawCreateClipper;
+
+extern HMODULE g_hmodCommonControls;
+extern FARPROC g_fpTrackMouseEvent;
+
+
+/*
+ * Screen privates macros
+ */
+
+#define winGetScreenPriv(pScreen) ((winPrivScreenPtr) \
+ dixLookupPrivate(&(pScreen)->devPrivates, g_iScreenPrivateKey))
+
+#define winSetScreenPriv(pScreen,v) \
+ dixSetPrivate(&(pScreen)->devPrivates, g_iScreenPrivateKey, v)
+
+#define winScreenPriv(pScreen) \
+ winPrivScreenPtr pScreenPriv = winGetScreenPriv(pScreen)
+
+
+/*
+ * Colormap privates macros
+ */
+
+#define winGetCmapPriv(pCmap) ((winPrivCmapPtr) \
+ dixLookupPrivate(&(pCmap)->devPrivates, g_iCmapPrivateKey))
+
+#define winSetCmapPriv(pCmap,v) \
+ dixSetPrivate(&(pCmap)->devPrivates, g_iCmapPrivateKey, v)
+
+#define winCmapPriv(pCmap) \
+ winPrivCmapPtr pCmapPriv = winGetCmapPriv(pCmap)
+
+
+/*
+ * GC privates macros
+ */
+
+#define winGetGCPriv(pGC) ((winPrivGCPtr) \
+ dixLookupPrivate(&(pGC)->devPrivates, g_iGCPrivateKey))
+
+#define winSetGCPriv(pGC,v) \
+ dixSetPrivate(&(pGC)->devPrivates, g_iGCPrivateKey, v)
+
+#define winGCPriv(pGC) \
+ winPrivGCPtr pGCPriv = winGetGCPriv(pGC)
+
+
+/*
+ * Pixmap privates macros
+ */
+
+#define winGetPixmapPriv(pPixmap) ((winPrivPixmapPtr) \
+ dixLookupPrivate(&(pPixmap)->devPrivates, g_iPixmapPrivateKey))
+
+#define winSetPixmapPriv(pPixmap,v) \
+ dixLookupPrivate(&(pPixmap)->devPrivates, g_iPixmapPrivateKey, v)
+
+#define winPixmapPriv(pPixmap) \
+ winPrivPixmapPtr pPixmapPriv = winGetPixmapPriv(pPixmap)
+
+
+/*
+ * Window privates macros
+ */
+
+#define winGetWindowPriv(pWin) ((winPrivWinPtr) \
+ dixLookupPrivate(&(pWin)->devPrivates, g_iWindowPrivateKey))
+
+#define winSetWindowPriv(pWin,v) \
+ dixLookupPrivate(&(pWin)->devPrivates, g_iWindowPrivateKey, v)
+
+#define winWindowPriv(pWin) \
+ winPrivWinPtr pWinPriv = winGetWindowPriv(pWin)
+
+/*
+ * wrapper macros
+ */
+#define _WIN_WRAP(priv, real, mem, func) {\
+ priv->mem = real->mem; \
+ real->mem = func; \
+}
+
+#define _WIN_UNWRAP(priv, real, mem) {\
+ real->mem = priv->mem; \
+}
+
+#define WIN_WRAP(mem, func) _WIN_WRAP(pScreenPriv, pScreen, mem, func)
+
+#define WIN_UNWRAP(mem) _WIN_UNWRAP(pScreenPriv, pScreen, mem)
+
+/*
+ * BEGIN DDX and DIX Function Prototypes
+ */
+
+
+/*
+ * winallpriv.c
+ */
+
+Bool
+winAllocatePrivates (ScreenPtr pScreen);
+
+Bool
+winInitCmapPrivates (ColormapPtr pCmap, int index);
+
+Bool
+winAllocateCmapPrivates (ColormapPtr pCmap);
+
+
+/*
+ * winauth.c
+ */
+
+#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+Bool
+winGenerateAuthorization (void);
+void winSetAuthorization(void);
+#endif
+
+
+/*
+ * winblock.c
+ */
+
+void
+winBlockHandler (int nScreen,
+ pointer pBlockData,
+ pointer pTimeout,
+ pointer pReadMask);
+
+
+#ifdef XWIN_NATIVEGDI
+/*
+ * winclip.c
+ */
+
+RegionPtr
+winPixmapToRegionNativeGDI (PixmapPtr pPix);
+#endif
+
+
+#ifdef XWIN_CLIPBOARD
+/*
+ * winclipboardinit.c
+ */
+
+Bool
+winInitClipboard (void);
+
+void
+winFixClipboardChain (void);
+#endif
+
+
+/*
+ * wincmap.c
+ */
+
+void
+winSetColormapFunctions (ScreenPtr pScreen);
+
+Bool
+winCreateDefColormap (ScreenPtr pScreen);
+
+
+/*
+ * wincreatewnd.c
+ */
+
+Bool
+winCreateBoundingWindowFullScreen (ScreenPtr pScreen);
+
+Bool
+winCreateBoundingWindowWindowed (ScreenPtr pScreen);
+
+
+/*
+ * windialogs.c
+ */
+
+int
+GetLiveClients (winPrivScreenPtr pScreenPriv);
+
+void
+winDisplayExitDialog (winPrivScreenPtr pScreenPriv);
+
+void
+winDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv);
+
+void
+winDisplayAboutDialog (winPrivScreenPtr pScreenPriv);
+
+
+/*
+ * winengine.c
+ */
+
+void
+winDetectSupportedEngines (void);
+
+Bool
+winSetEngine (ScreenPtr pScreen);
+
+Bool
+winGetDDProcAddresses (void);
+
+
+/*
+ * winerror.c
+ */
+
+#ifdef DDXOSVERRORF
+void
+OSVenderVErrorF (const char *pszFormat, va_list va_args);
+#endif
+
+void
+winMessageBoxF (const char *pszError, UINT uType, ...);
+
+
+#ifdef XWIN_NATIVEGDI
+/*
+ * winfillsp.c
+ */
+
+void
+winFillSpansNativeGDI (DrawablePtr pDrawable,
+ GCPtr pGC,
+ int nSpans,
+ DDXPointPtr pPoints,
+ int *pWidths,
+ int fSorted);
+#endif
+
+
+#ifdef XWIN_NATIVEGDI
+/*
+ * winfont.c
+ */
+
+Bool
+winRealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont);
+
+Bool
+winUnrealizeFontNativeGDI (ScreenPtr pScreen, FontPtr pFont);
+#endif
+
+
+#ifdef XWIN_NATIVEGDI
+/*
+ * wingc.c
+ */
+
+Bool
+winCreateGCNativeGDI (GCPtr pGC);
+#endif
+
+
+#ifdef XWIN_NATIVEGDI
+/*
+ * wingetsp.c
+ */
+
+void
+winGetSpansNativeGDI (DrawablePtr pDrawable,
+ int wMax,
+ DDXPointPtr pPoints,
+ int *pWidths,
+ int nSpans,
+ char *pDst);
+#endif
+
+
+/*
+ * winglobals.c
+ */
+
+void
+winInitializeGlobals (void);
+
+
+/*
+ * winkeybd.c
+ */
+
+void
+winTranslateKey (WPARAM wParam, LPARAM lParam, int *piScanCode);
+
+int
+winKeybdProc (DeviceIntPtr pDeviceInt, int iState);
+
+void
+winInitializeModeKeyStates (void);
+
+void
+winRestoreModeKeyStates (void);
+
+Bool
+winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam);
+
+void
+winKeybdReleaseKeys (void);
+
+void
+winSendKeyEvent (DWORD dwKey, Bool fDown);
+
+BOOL
+winCheckKeyPressed(WPARAM wParam, LPARAM lParam);
+
+void
+winFixShiftKeys (int iScanCode);
+
+/*
+ * winkeyhook.c
+ */
+
+Bool
+winInstallKeyboardHookLL (void);
+
+void
+winRemoveKeyboardHookLL (void);
+
+
+/*
+ * winmisc.c
+ */
+
+#ifdef XWIN_NATIVEGDI
+void
+winQueryBestSizeNativeGDI (int class, unsigned short *pWidth,
+ unsigned short *pHeight, ScreenPtr pScreen);
+#endif
+
+CARD8
+winCountBits (DWORD dw);
+
+Bool
+winUpdateFBPointer (ScreenPtr pScreen, void *pbits);
+
+#ifdef XWIN_NATIVEGDI
+BOOL
+winPaintBackground (HWND hwnd, COLORREF colorref);
+#endif
+
+
+/*
+ * winmouse.c
+ */
+
+int
+winMouseProc (DeviceIntPtr pDeviceInt, int iState);
+
+int
+winMouseWheel (ScreenPtr pScreen, int iDeltaZ);
+
+void
+winMouseButtonsSendEvent (int iEventType, int iButton);
+
+int
+winMouseButtonsHandle (ScreenPtr pScreen,
+ int iEventType, int iButton,
+ WPARAM wParam);
+
+void
+winEnqueueMotion(int x, int y);
+
+#ifdef XWIN_NATIVEGDI
+/*
+ * winnativegdi.c
+ */
+
+HBITMAP
+winCreateDIBNativeGDI (int iWidth, int iHeight, int iDepth,
+ BYTE **ppbBits, BITMAPINFO **ppbmi);
+
+Bool
+winSetEngineFunctionsNativeGDI (ScreenPtr pScreen);
+#endif
+
+
+#ifdef XWIN_PRIMARYFB
+/*
+ * winpfbddd.c
+ */
+
+Bool
+winSetEngineFunctionsPrimaryDD (ScreenPtr pScreen);
+#endif
+
+
+#ifdef XWIN_NATIVEGDI
+/*
+ * winpixmap.c
+ */
+
+PixmapPtr
+winCreatePixmapNativeGDI (ScreenPtr pScreen, int width, int height, int depth,
+ unsigned usage_hint);
+
+Bool
+winDestroyPixmapNativeGDI (PixmapPtr pPixmap);
+
+Bool
+winModifyPixmapHeaderNativeGDI (PixmapPtr pPixmap,
+ int iWidth, int iHeight,
+ int iDepth,
+ int iBitsPerPixel,
+ int devKind,
+ pointer pPixData);
+#endif
+
+#ifdef XWIN_NATIVEGDI
+/*
+ * winpolyline.c
+ */
+
+void
+winPolyLineNativeGDI (DrawablePtr pDrawable,
+ GCPtr pGC,
+ int mode,
+ int npt,
+ DDXPointPtr ppt);
+#endif
+
+
+#ifdef XWIN_NATIVEGDI
+/*
+ * winpushpxl.c
+ */
+
+void
+winPushPixels (GCPtr pGC, PixmapPtr pBitMap, DrawablePtr pDrawable,
+ int dx, int dy, int xOrg, int yOrg);
+#endif
+
+
+/*
+ * winscrinit.c
+ */
+
+Bool
+winScreenInit (int index,
+ ScreenPtr pScreen,
+ int argc, char **argv);
+
+Bool
+winFinishScreenInitFB (int index,
+ ScreenPtr pScreen,
+ int argc, char **argv);
+
+#if defined(XWIN_NATIVEGDI)
+Bool
+winFinishScreenInitNativeGDI (int index,
+ ScreenPtr pScreen,
+ int argc, char **argv);
+#endif
+
+
+#ifdef XWIN_NATIVEGDI
+/*
+ * winsetsp.c
+ */
+
+void
+winSetSpansNativeGDI (DrawablePtr pDrawable,
+ GCPtr pGC,
+ char *pSrc,
+ DDXPointPtr pPoints,
+ int *pWidth,
+ int nSpans,
+ int fSorted);
+#endif
+
+
+/*
+ * winshaddd.c
+ */
+
+Bool
+winSetEngineFunctionsShadowDD (ScreenPtr pScreen);
+
+
+/*
+ * winshadddnl.c
+ */
+
+Bool
+winSetEngineFunctionsShadowDDNL (ScreenPtr pScreen);
+
+
+/*
+ * winshadgdi.c
+ */
+
+Bool
+winSetEngineFunctionsShadowGDI (ScreenPtr pScreen);
+
+
+/*
+ * winwakeup.c
+ */
+
+void
+winWakeupHandler (int nScreen,
+ pointer pWakeupData,
+ unsigned long ulResult,
+ pointer pReadmask);
+
+
+/*
+ * winwindow.c
+ */
+
+#ifdef XWIN_NATIVEGDI
+Bool
+winCreateWindowNativeGDI (WindowPtr pWin);
+
+Bool
+winDestroyWindowNativeGDI (WindowPtr pWin);
+
+Bool
+winPositionWindowNativeGDI (WindowPtr pWin, int x, int y);
+
+void
+winCopyWindowNativeGDI (WindowPtr pWin,
+ DDXPointRec ptOldOrg,
+ RegionPtr prgnSrc);
+
+Bool
+winChangeWindowAttributesNativeGDI (WindowPtr pWin, unsigned long mask);
+
+Bool
+winUnmapWindowNativeGDI (WindowPtr pWindow);
+
+Bool
+winMapWindowNativeGDI (WindowPtr pWindow);
+#endif
+
+Bool
+winCreateWindowRootless (WindowPtr pWindow);
+
+Bool
+winDestroyWindowRootless (WindowPtr pWindow);
+
+Bool
+winPositionWindowRootless (WindowPtr pWindow, int x, int y);
+
+Bool
+winChangeWindowAttributesRootless (WindowPtr pWindow, unsigned long mask);
+
+Bool
+winUnmapWindowRootless (WindowPtr pWindow);
+
+Bool
+winMapWindowRootless (WindowPtr pWindow);
+
+void
+winSetShapeRootless (WindowPtr pWindow);
+
+
+/*
+ * winmultiwindowicons.c - Used by both multi-window and Win32Rootless
+ */
+
+HICON
+winXIconToHICON (WindowPtr pWin, int iconSize);
+
+void
+winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon);
+
+#ifdef XWIN_MULTIWINDOW
+/*
+ * winmultiwindowshape.c
+ */
+
+void
+winReshapeMultiWindow (WindowPtr pWin);
+
+void
+winSetShapeMultiWindow (WindowPtr pWindow);
+
+void
+winUpdateRgnMultiWindow (WindowPtr pWindow);
+#endif
+
+
+#ifdef XWIN_MULTIWINDOW
+/*
+ * winmultiwindowwindow.c
+ */
+
+Bool
+winCreateWindowMultiWindow (WindowPtr pWindow);
+
+Bool
+winDestroyWindowMultiWindow (WindowPtr pWindow);
+
+Bool
+winPositionWindowMultiWindow (WindowPtr pWindow, int x, int y);
+
+Bool
+winChangeWindowAttributesMultiWindow (WindowPtr pWindow, unsigned long mask);
+
+Bool
+winUnmapWindowMultiWindow (WindowPtr pWindow);
+
+Bool
+winMapWindowMultiWindow (WindowPtr pWindow);
+
+void
+winReparentWindowMultiWindow (WindowPtr pWin, WindowPtr pPriorParent);
+
+void
+winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib);
+
+void
+winReorderWindowsMultiWindow (void);
+
+void
+winResizeWindowMultiWindow (WindowPtr pWin, int x, int y, unsigned int w,
+ unsigned int h, WindowPtr pSib);
+void
+winMoveWindowMultiWindow (WindowPtr pWin, int x, int y,
+ WindowPtr pSib, VTKind kind);
+
+void
+winCopyWindowMultiWindow (WindowPtr pWin, DDXPointRec oldpt,
+ RegionPtr oldRegion);
+
+XID
+winGetWindowID (WindowPtr pWin);
+
+int
+winAdjustXWindow (WindowPtr pWin, HWND hwnd);
+#endif
+
+
+#ifdef XWIN_MULTIWINDOW
+/*
+ * winmultiwindowwndproc.c
+ */
+
+LRESULT CALLBACK
+winTopLevelWindowProc (HWND hwnd, UINT message,
+ WPARAM wParam, LPARAM lParam);
+#endif
+
+
+/*
+ * wintrayicon.c
+ */
+
+void
+winInitNotifyIcon (winPrivScreenPtr pScreenPriv, Bool Modify);
+
+void
+winDeleteNotifyIcon (winPrivScreenPtr pScreenPriv);
+
+LRESULT
+winHandleIconMessage (HWND hwnd, UINT message,
+ WPARAM wParam, LPARAM lParam,
+ winPrivScreenPtr pScreenPriv);
+
+
+/*
+ * winwndproc.c
+ */
+
+LRESULT CALLBACK
+winWindowProc (HWND hWnd, UINT message,
+ WPARAM wParam, LPARAM lParam);
+
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+/*
+ * winwin32rootless.c
+ */
+
+Bool
+winMWExtWMCreateFrame (RootlessWindowPtr pFrame, ScreenPtr pScreen,
+ int newX, int newY, RegionPtr pShape);
+
+void
+winMWExtWMDestroyFrame (RootlessFrameID wid);
+
+void
+winMWExtWMMoveFrame (RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY);
+
+void
+winMWExtWMResizeFrame (RootlessFrameID wid, ScreenPtr pScreen,
+ int newX, int newY, unsigned int newW, unsigned int newH,
+ unsigned int gravity);
+
+void
+winMWExtWMRestackFrame (RootlessFrameID wid, RootlessFrameID nextWid);
+
+void
+winMWExtWMReshapeFrame (RootlessFrameID wid, RegionPtr pShape);
+
+void
+winMWExtWMUnmapFrame (RootlessFrameID wid);
+
+void
+winMWExtWMStartDrawing (RootlessFrameID wid, char **pixelData, int *bytesPerRow);
+
+void
+winMWExtWMStopDrawing (RootlessFrameID wid, Bool flush);
+
+void
+winMWExtWMUpdateRegion (RootlessFrameID wid, RegionPtr pDamage);
+
+void
+winMWExtWMDamageRects (RootlessFrameID wid, int count, const BoxRec *rects,
+ int shift_x, int shift_y);
+
+void
+winMWExtWMRootlessSwitchWindow (RootlessWindowPtr pFrame, WindowPtr oldWin);
+
+void
+winMWExtWMCopyBytes (unsigned int width, unsigned int height,
+ const void *src, unsigned int srcRowBytes,
+ void *dst, unsigned int dstRowBytes);
+
+void
+winMWExtWMFillBytes (unsigned int width, unsigned int height, unsigned int value,
+ void *dst, unsigned int dstRowBytes);
+
+int
+winMWExtWMCompositePixels (unsigned int width, unsigned int height, unsigned int function,
+ void *src[2], unsigned int srcRowBytes[2],
+ void *mask, unsigned int maskRowBytes,
+ void *dst[2], unsigned int dstRowBytes[2]);
+
+void
+winMWExtWMCopyWindow (RootlessFrameID wid, int dstNrects, const BoxRec *dstRects,
+ int dx, int dy);
+#endif
+
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+/*
+ * winwin32rootlesswindow.c
+ */
+
+void
+winMWExtWMReorderWindows (ScreenPtr pScreen);
+
+void
+winMWExtWMMoveXWindow (WindowPtr pWin, int x, int y);
+
+void
+winMWExtWMResizeXWindow (WindowPtr pWin, int w, int h);
+
+void
+winMWExtWMMoveResizeXWindow (WindowPtr pWin, int x, int y, int w, int h);
+
+void
+winMWExtWMUpdateIcon (Window id);
+
+void
+winMWExtWMUpdateWindowDecoration (win32RootlessWindowPtr pRLWinPriv,
+ winScreenInfoPtr pScreenInfo);
+
+wBOOL CALLBACK
+winMWExtWMDecorateWindow (HWND hwnd, LPARAM lParam);
+
+Bool
+winIsInternalWMRunning (winScreenInfoPtr pScreenInfo);
+
+void
+winMWExtWMRestackWindows (ScreenPtr pScreen);
+#endif
+
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+/*
+ * winwin32rootlesswndproc.c
+ */
+
+LRESULT CALLBACK
+winMWExtWMWindowProc (HWND hwnd, UINT message,
+ WPARAM wParam, LPARAM lParam);
+#endif
+
+
+/*
+ * winwindowswm.c
+ */
+
+void
+winWindowsWMSendEvent (int type, unsigned int mask, int which, int arg,
+ Window window, int x, int y, int w, int h);
+
+void
+winWindowsWMExtensionInit (void);
+
+/*
+ * wincursor.c
+ */
+
+Bool
+winInitCursor (ScreenPtr pScreen);
+
+/*
+ * END DDX and DIX Function Prototypes
+ */
+
+#endif /* _WIN_H_ */
+
diff --git a/xorg-server/hw/xwin/winauth.c b/xorg-server/hw/xwin/winauth.c index 97b3a85fe..fca6da086 100644 --- a/xorg-server/hw/xwin/winauth.c +++ b/xorg-server/hw/xwin/winauth.c @@ -1,131 +1,215 @@ -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#if defined(XCSECURITY) -/* - *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of Harold L Hunt II - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from Harold L Hunt II. - * - * Authors: Harold L Hunt II - */ - -#include "win.h" - -/* Includes for authorization */ -#include <X11/Xauth.h> -#include "securitysrv.h" -#include <X11/extensions/securstr.h> - - -/* - * Constants - */ - -#define AUTH_NAME "MIT-MAGIC-COOKIE-1" - - -/* - * Globals - */ - -XID g_authId = 0; -unsigned int g_uiAuthDataLen = 0; -char *g_pAuthData = NULL; - - -/* - * Generate authorization cookie for internal server clients - */ - -Bool -winGenerateAuthorization () -{ - Bool fFreeAuth = FALSE; - SecurityAuthorizationPtr pAuth = NULL; - - /* Call OS layer to generate authorization key */ - g_authId = GenerateAuthorization (strlen (AUTH_NAME), - AUTH_NAME, - 0, - NULL, - &g_uiAuthDataLen, - &g_pAuthData); - if ((XID) ~0L == g_authId) - { - ErrorF ("winGenerateAuthorization - GenerateAuthorization failed\n"); - goto auth_bailout; - } -#ifdef WINDBG - else - { - winDebug ("winGenerateAuthorization - GenerateAuthorization success!\n" - "AuthDataLen: %d AuthData: %s\n", - g_uiAuthDataLen, g_pAuthData); - } -#endif - - /* Allocate structure for additional auth information */ - pAuth = (SecurityAuthorizationPtr) - xalloc (sizeof (SecurityAuthorizationRec)); - if (!(pAuth)) - { - ErrorF ("winGenerateAuthorization - Failed allocating " - "SecurityAuthorizationPtr.\n"); - goto auth_bailout; - } - - /* Fill in the auth fields */ - pAuth->id = g_authId; - pAuth->timeout = 0; /* live for x seconds after refcnt == 0 */ - pAuth->group = None; - pAuth->trustLevel = XSecurityClientTrusted; - pAuth->refcnt = 1; /* this auth must stick around */ - pAuth->secondsRemaining = 0; - pAuth->timer = NULL; - pAuth->eventClients = NULL; - - /* Add the authorization to the server's auth list */ - if (!AddResource (g_authId, - SecurityAuthorizationResType, - pAuth)) - { - ErrorF ("winGenerateAuthorization - AddResource failed for auth.\n"); - fFreeAuth = TRUE; - goto auth_bailout; - } - - /* Don't free the auth data, since it is still used internally */ - pAuth = NULL; - - return TRUE; - - auth_bailout: - if (fFreeAuth) - xfree (pAuth); - - return FALSE; -} -#endif +/*
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of Harold L Hunt II
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from Harold L Hunt II.
+ *
+ * Authors: Harold L Hunt II
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+
+#include "win.h"
+
+/* Includes for authorization */
+#include "securitysrv.h"
+
+/*
+ * Constants
+ */
+
+#define AUTH_NAME "MIT-MAGIC-COOKIE-1"
+
+
+/*
+ * Locals
+ */
+
+static XID g_authId = 0;
+static unsigned int g_uiAuthDataLen = 0;
+static char *g_pAuthData = NULL;
+
+/*
+ * Code to generate a MIT-MAGIC-COOKIE-1, copied from under XCSECURITY
+ */
+
+
+
+#ifndef XCSECURITY
+static
+void
+GenerateRandomData (int len, char *buf)
+{
+ int fd;
+#ifdef _MSC_VER
+ static HANDLE hAdvApi32;
+ static BOOLEAN (_stdcall * RtlGenRandom)(void *,unsigned long);
+
+ if (!hAdvApi32)
+ {
+ hAdvApi32=LoadLibrary("advapi32.dll");
+ RtlGenRandom=(BOOLEAN (_stdcall *)(void*,unsigned long))GetProcAddress(hAdvApi32,"SystemFunction036");
+ }
+ RtlGenRandom(buf, len);
+#else
+ fd = open("/dev/urandom", O_RDONLY);
+ read(fd, buf, len);
+ close(fd);
+#endif
+}
+
+
+static char cookie[16]; /* 128 bits */
+
+XID
+static MitGenerateCookie (
+ unsigned data_length,
+ char *data,
+ XID id,
+ unsigned *data_length_return,
+ char **data_return)
+{
+ int i = 0;
+ int status;
+
+ while (data_length--)
+ {
+ cookie[i++] += *data++;
+ if (i >= sizeof (cookie)) i = 0;
+ }
+ GenerateRandomData(sizeof (cookie), cookie);
+ status = MitAddCookie(sizeof (cookie), cookie, id);
+ if (!status)
+ {
+ id = -1;
+ }
+ else
+ {
+ *data_return = cookie;
+ *data_length_return = sizeof (cookie);
+ }
+ return id;
+}
+
+static
+XID
+GenerateAuthorization(
+ unsigned name_length,
+ char *name,
+ unsigned data_length,
+ char *data,
+ unsigned *data_length_return,
+ char **data_return)
+{
+ return MitGenerateCookie(data_length, data,
+ FakeClientID(0), data_length_return, data_return);
+}
+#endif
+
+/*
+ * Generate authorization cookie for internal server clients
+ */
+
+Bool
+winGenerateAuthorization ()
+{
+ Bool fFreeAuth = FALSE;
+ SecurityAuthorizationPtr pAuth = NULL;
+
+ /* Call OS layer to generate authorization key */
+ g_authId = GenerateAuthorization (strlen (AUTH_NAME),
+ AUTH_NAME,
+ 0,
+ NULL,
+ &g_uiAuthDataLen,
+ &g_pAuthData);
+ if ((XID) ~0L == g_authId)
+ {
+ ErrorF ("winGenerateAuthorization - GenerateAuthorization failed\n");
+ goto auth_bailout;
+ }
+#ifdef WINDBG
+ else
+ {
+ winDebug("winGenerateAuthorization - GenerateAuthorization success!\n"
+ "AuthDataLen: %d AuthData: %s\n",
+ g_uiAuthDataLen, g_pAuthData);
+ }
+#endif
+
+#ifdef XCSECURITY
+ /* Allocate structure for additional auth information */
+ pAuth = (SecurityAuthorizationPtr)
+ xalloc (sizeof (SecurityAuthorizationRec));
+ if (!(pAuth))
+ {
+ ErrorF ("winGenerateAuthorization - Failed allocating "
+ "SecurityAuthorizationPtr.\n");
+ goto auth_bailout;
+ }
+
+ /* Fill in the auth fields */
+ pAuth->id = g_authId;
+ pAuth->timeout = 0; /* live for x seconds after refcnt == 0 */
+ pAuth->group = None;
+ pAuth->trustLevel = XSecurityClientTrusted;
+ pAuth->refcnt = 1; /* this auth must stick around */
+ pAuth->secondsRemaining = 0;
+ pAuth->timer = NULL;
+ pAuth->eventClients = NULL;
+
+ /* Add the authorization to the server's auth list */
+ if (!AddResource (g_authId,
+ SecurityAuthorizationResType,
+ pAuth))
+ {
+ ErrorF ("winGenerateAuthorization - AddResource failed for auth.\n");
+ fFreeAuth = TRUE;
+ goto auth_bailout;
+ }
+
+ /* Don't free the auth data, since it is still used internally */
+ pAuth = NULL;
+#endif
+
+ return TRUE;
+
+ auth_bailout:
+ if (fFreeAuth)
+ xfree (pAuth);
+
+ return FALSE;
+}
+
+/* Use our generated cookie for authentication */
+void
+winSetAuthorization(void)
+{
+ XSetAuthorization (AUTH_NAME,
+ strlen (AUTH_NAME),
+ g_pAuthData,
+ g_uiAuthDataLen);
+}
diff --git a/xorg-server/hw/xwin/winclipboardtextconv.c b/xorg-server/hw/xwin/winclipboardtextconv.c index 16637a592..487df81ef 100644 --- a/xorg-server/hw/xwin/winclipboardtextconv.c +++ b/xorg-server/hw/xwin/winclipboardtextconv.c @@ -1,159 +1,155 @@ -/* - *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of Harold L Hunt II - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from Harold L Hunt II. - * - * Authors: Harold L Hunt II - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" -#include <stdio.h> -#include <stdlib.h> - -void -winClipboardDOStoUNIX (char *pszSrc, int iLength); -void -winClipboardUNIXtoDOS (unsigned char **ppszData, int iLength); - -/* - * Convert \r\n to \n - * - * NOTE: This was heavily inspired by, Cygwin's - * winsup/cygwin/fhandler.cc/fhandler_base::read () - */ - -void -winClipboardDOStoUNIX (char *pszSrc, int iLength) -{ - char *pszDest = pszSrc; - char *pszEnd = pszSrc + iLength; - - /* Loop until the last character */ - while (pszSrc < pszEnd) - { - /* Copy the current source character to current destination character */ - *pszDest = *pszSrc; - - /* Advance to the next source character */ - pszSrc++; - - /* Don't advance the destination character if we need to drop an \r */ - if (*pszDest != '\r' || *pszSrc != '\n') - pszDest++; - } - - /* Move the terminating null */ - *pszDest = '\0'; -} - - -/* - * Convert \n to \r\n - */ - -void -winClipboardUNIXtoDOS (unsigned char **ppszData, int iLength) -{ - int iNewlineCount = 0; - unsigned char *pszSrc = *ppszData; - unsigned char *pszEnd = pszSrc + iLength; - unsigned char *pszDest = NULL, *pszDestBegin = NULL; - -#ifdef WINDBG - winDebug ("UNIXtoDOS () - Original data:\n%s\n", *ppszData); -#endif - - /* Count \n characters without leading \r */ - while (pszSrc < pszEnd) - { - /* Skip ahead two character if found set of \r\n */ - if (*pszSrc == '\r' && pszSrc + 1 < pszEnd && *(pszSrc + 1) == '\n') - { - pszSrc += 2; - continue; - } - - /* Increment the count if found naked \n */ - if (*pszSrc == '\n') - { - iNewlineCount++; - } - - pszSrc++; - } - - /* Return if no naked \n's */ - if (iNewlineCount == 0) - return; - - /* Allocate a new string */ - pszDestBegin = pszDest = malloc (iLength + iNewlineCount + 1); - - /* Set source pointer to beginning of data string */ - pszSrc = *ppszData; - - /* Loop through all characters in source string */ - while (pszSrc < pszEnd) - { - /* Copy line endings that are already valid */ - if (*pszSrc == '\r' && pszSrc + 1 < pszEnd && *(pszSrc + 1) == '\n') - { - *pszDest = *pszSrc; - *(pszDest + 1) = *(pszSrc + 1); - pszDest += 2; - pszSrc += 2; - continue; - } - - /* Add \r to naked \n's */ - if (*pszSrc == '\n') - { - *pszDest = '\r'; - *(pszDest + 1) = *pszSrc; - pszDest += 2; - pszSrc += 1; - continue; - } - - /* Copy normal characters */ - *pszDest = *pszSrc; - pszSrc++; - pszDest++; - } - - /* Put terminating null at end of new string */ - *pszDest = '\0'; - - /* Swap string pointers */ - free (*ppszData); - *ppszData = pszDestBegin; - -#ifdef WINDBG - winDebug ("UNIXtoDOS () - Final string:\n%s\n", pszDestBegin); -#endif -} +/*
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of Harold L Hunt II
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from Harold L Hunt II.
+ *
+ * Authors: Harold L Hunt II
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+void
+winClipboardDOStoUNIX (char *pszSrc, int iLength);
+void
+winClipboardUNIXtoDOS (unsigned char **ppszData, int iLength);
+
+/*
+ * Convert \r\n to \n
+ *
+ * NOTE: This was heavily inspired by, Cygwin's
+ * winsup/cygwin/fhandler.cc/fhandler_base::read ()
+ */
+
+void
+winClipboardDOStoUNIX (char *pszSrc, int iLength)
+{
+ char *pszDest = pszSrc;
+ char *pszEnd = pszSrc + iLength;
+
+ /* Loop until the last character */
+ while (pszSrc < pszEnd)
+ {
+ /* Copy the current source character to current destination character */
+ *pszDest = *pszSrc;
+
+ /* Advance to the next source character */
+ pszSrc++;
+
+ /* Don't advance the destination character if we need to drop an \r */
+ if (*pszDest != '\r' || *pszSrc != '\n')
+ pszDest++;
+ }
+
+ /* Move the terminating null */
+ *pszDest = '\0';
+}
+
+
+/*
+ * Convert \n to \r\n
+ */
+
+void
+winClipboardUNIXtoDOS (unsigned char **ppszData, int iLength)
+{
+ int iNewlineCount = 0;
+ unsigned char *pszSrc = *ppszData;
+ unsigned char *pszEnd = pszSrc + iLength;
+ unsigned char *pszDest = NULL, *pszDestBegin = NULL;
+
+ winDebug("UNIXtoDOS () - Original data:'%s'\n", *ppszData);
+
+ /* Count \n characters without leading \r */
+ while (pszSrc < pszEnd)
+ {
+ /* Skip ahead two character if found set of \r\n */
+ if (*pszSrc == '\r' && pszSrc + 1 < pszEnd && *(pszSrc + 1) == '\n')
+ {
+ pszSrc += 2;
+ continue;
+ }
+
+ /* Increment the count if found naked \n */
+ if (*pszSrc == '\n')
+ {
+ iNewlineCount++;
+ }
+
+ pszSrc++;
+ }
+
+ /* Return if no naked \n's */
+ if (iNewlineCount == 0)
+ return;
+
+ /* Allocate a new string */
+ pszDestBegin = pszDest = malloc (iLength + iNewlineCount + 1);
+
+ /* Set source pointer to beginning of data string */
+ pszSrc = *ppszData;
+
+ /* Loop through all characters in source string */
+ while (pszSrc < pszEnd)
+ {
+ /* Copy line endings that are already valid */
+ if (*pszSrc == '\r' && pszSrc + 1 < pszEnd && *(pszSrc + 1) == '\n')
+ {
+ *pszDest = *pszSrc;
+ *(pszDest + 1) = *(pszSrc + 1);
+ pszDest += 2;
+ pszSrc += 2;
+ continue;
+ }
+
+ /* Add \r to naked \n's */
+ if (*pszSrc == '\n')
+ {
+ *pszDest = '\r';
+ *(pszDest + 1) = *pszSrc;
+ pszDest += 2;
+ pszSrc += 1;
+ continue;
+ }
+
+ /* Copy normal characters */
+ *pszDest = *pszSrc;
+ pszSrc++;
+ pszDest++;
+ }
+
+ /* Put terminating null at end of new string */
+ *pszDest = '\0';
+
+ /* Swap string pointers */
+ free (*ppszData);
+ *ppszData = pszDestBegin;
+
+ winDebug("UNIXtoDOS () - Final string:'%s'\n", pszDestBegin);
+}
diff --git a/xorg-server/hw/xwin/winclipboardthread.c b/xorg-server/hw/xwin/winclipboardthread.c index fcae5f851..80381ac51 100644 --- a/xorg-server/hw/xwin/winclipboardthread.c +++ b/xorg-server/hw/xwin/winclipboardthread.c @@ -38,7 +38,6 @@ #ifdef __CYGWIN__
#include <errno.h>
#endif
-#include "X11/Xauth.h"
#include "misc.h"
#include "winmsg.h"
@@ -47,22 +46,11 @@ #endif
/*
- * Constants
- */
-
-#define AUTH_NAME "MIT-MAGIC-COOKIE-1"
-
-
-/*
* References to external symbols
*/
extern Bool g_fUnicodeClipboard;
extern unsigned long serverGeneration;
-#if defined(XCSECURITY)
-extern unsigned int g_uiAuthDataLen;
-extern char *g_pAuthData;
-#endif
extern Bool g_fClipboardLaunched;
extern Bool g_fClipboardStarted;
extern HWND g_hwndClipboard;
@@ -158,13 +146,8 @@ winClipboardProc (void *pvNotUsed) //goto thread_errorexit;
}
-#if defined(XCSECURITY)
/* Use our generated cookie for authentication */
- XSetAuthorization (AUTH_NAME,
- strlen (AUTH_NAME),
- g_pAuthData,
- g_uiAuthDataLen);
-#endif
+ winSetAuthorization();
/* Set error handler */
XSetErrorHandler (winClipboardErrorHandler);
diff --git a/xorg-server/hw/xwin/winclipboardwndproc.c b/xorg-server/hw/xwin/winclipboardwndproc.c index 2898b423d..dbfc61e4e 100644 --- a/xorg-server/hw/xwin/winclipboardwndproc.c +++ b/xorg-server/hw/xwin/winclipboardwndproc.c @@ -113,13 +113,13 @@ winProcessXEventsTimeout (HWND hwnd, int iWindow, Display *pDisplay, if (tv.tv_sec < 0)
return WIN_XEVENTS_SUCCESS;
- /* Wait for a Windows event or an X event */
+ /* Wait for an X event */
iReturn = select (iConnNumber + 1,/* Highest fds number */
&fdsRead, /* Read mask */
NULL, /* No write mask */
NULL, /* No exception mask */
&tv); /* No timeout */
- if (iReturn <= 0)
+ if (iReturn < 0)
{
ErrorF ("winProcessXEventsTimeout - Call to select () failed: %d (%x). "
"Bailing.\n", iReturn, WSAGetLastError());
@@ -403,9 +403,9 @@ winClipboardWindowProc (HWND hwnd, UINT message, * follow this message and reassert ownership of the X11
* selections, handling the issue for us.
*/
+ winDebug ("winClipboardWindowProc - WM_DESTROYCLIPBOARD - Ignored.\n");
return 0;
-
case WM_RENDERFORMAT:
case WM_RENDERALLFORMATS:
{
@@ -495,6 +495,8 @@ winClipboardWindowProc (HWND hwnd, UINT message, if (g_fUnicodeSupport)
SetClipboardData (CF_UNICODETEXT, NULL);
SetClipboardData (CF_TEXT, NULL);
+
+ ErrorF("winClipboardWindowProc - timed out waiting for WIN_XEVENTS_NOTIFY\n");
}
/* Special handling for WM_RENDERALLFORMATS */
diff --git a/xorg-server/hw/xwin/winclipboardwrappers.c b/xorg-server/hw/xwin/winclipboardwrappers.c index a096a2a51..172365d27 100644 --- a/xorg-server/hw/xwin/winclipboardwrappers.c +++ b/xorg-server/hw/xwin/winclipboardwrappers.c @@ -1,494 +1,494 @@ -/* - *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. - *Copyright (C) Colin Harrison 2005-2008 - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of the copyright holder(s) - *and author(s) shall not be used in advertising or otherwise to promote - *the sale, use or other dealings in this Software without prior written - *authorization from the copyright holder(s) and author(s). - * - * Authors: Harold L Hunt II - * Colin Harrison - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" -#include "dixstruct.h" -#include <X11/Xatom.h> - - -/* - * Constants - */ - -#define CLIP_NUM_CALLS 4 -#define CLIP_NUM_SELECTIONS 2 -#define CLIP_OWN_PRIMARY 0 -#define CLIP_OWN_CLIPBOARD 1 - - -/* - * Local function prototypes - */ - -DISPATCH_PROC(winProcEstablishConnection); -DISPATCH_PROC(winProcQueryTree); -DISPATCH_PROC(winProcSetSelectionOwner); - - -/* - * References to external symbols - */ - -extern Bool g_fUnicodeSupport; -extern int g_iNumScreens; -extern unsigned int g_uiAuthDataLen; -extern char *g_pAuthData; -extern Bool g_fXdmcpEnabled; -extern Bool g_fClipboardLaunched; -extern Bool g_fClipboardStarted; -extern Bool g_fClipboard; -extern Window g_iClipboardWindow; -extern Atom g_atomLastOwnedSelection; -extern HWND g_hwndClipboard; - -extern winDispatchProcPtr winProcEstablishConnectionOrig; -extern winDispatchProcPtr winProcQueryTreeOrig; -extern winDispatchProcPtr winProcSetSelectionOwnerOrig; - - -/* - * Wrapper for internal QueryTree function. - * Hides the clipboard client when it is the only client remaining. - */ - -int -winProcQueryTree (ClientPtr client) -{ - int iReturn; - - winDebug ("winProcQueryTree - Hello\n"); - - /* - * This procedure is only used for initialization. - * We can unwrap the original procedure at this point - * so that this function is no longer called until the - * server resets and the function is wrapped again. - */ - ProcVector[X_QueryTree] = winProcQueryTreeOrig; - - /* - * Call original function and bail if it fails. - * NOTE: We must do this first, since we need XdmcpOpenDisplay - * to be called before we initialize our clipboard client. - */ - iReturn = (*winProcQueryTreeOrig) (client); - if (iReturn != 0) - { - ErrorF ("winProcQueryTree - ProcQueryTree failed, bailing.\n"); - return iReturn; - } - - /* Make errors more obvious */ - winProcQueryTreeOrig = NULL; - - /* Do nothing if clipboard is not enabled */ - if (!g_fClipboard) - { - winDebug ("winProcQueryTree - Clipboard is not enabled, " - "returning.\n"); - return iReturn; - } - - /* If the clipboard client has already been started, abort */ - if (g_fClipboardLaunched) - { - winDebug ("winProcQueryTree - Clipboard client already " - "launched, returning.\n"); - return iReturn; - } - - /* Startup the clipboard client if clipboard mode is being used */ - if (g_fXdmcpEnabled && g_fClipboard) - { - /* - * NOTE: The clipboard client is started here for a reason: - * 1) Assume you are using XDMCP (e.g. XWin -query %hostname%) - * 2) If the clipboard client attaches during X Server startup, - * then it becomes the "magic client" that causes the X Server - * to reset if it exits. - * 3) XDMCP calls KillAllClients when it starts up. - * 4) The clipboard client is a client, so it is killed. - * 5) The clipboard client is the "magic client", so the X Server - * resets itself. - * 6) This repeats ad infinitum. - * 7) We avoid this by waiting until at least one client (could - * be XDM, could be another client) connects, which makes it - * almost certain that the clipboard client will not connect - * until after XDM when using XDMCP. - * 8) Unfortunately, there is another problem. - * 9) XDM walks the list of windows with XQueryTree, - * killing any client it finds with a window. - * 10)Thus, when using XDMCP we wait until the first call - * to ProcQueryTree before we startup the clipboard client. - * This should prevent XDM from finding the clipboard client, - * since it has not yet created a window. - * 11)Startup when not using XDMCP is handled in - * winProcEstablishConnection. - */ - - /* Create the clipboard client thread */ - if (!winInitClipboard ()) - { - ErrorF ("winProcQueryTree - winClipboardInit " - "failed.\n"); - return iReturn; - } - - winDebug ("winProcQueryTree - winInitClipboard returned.\n"); - } - - /* Flag that clipboard client has been launched */ - g_fClipboardLaunched = TRUE; - - return iReturn; -} - - -/* - * Wrapper for internal EstablishConnection function. - * Initializes internal clients that must not be started until - * an external client has connected. - */ - -int -winProcEstablishConnection (ClientPtr client) -{ - int iReturn; - static int s_iCallCount = 0; - static unsigned long s_ulServerGeneration = 0; - - #ifdef WINDBG - if (s_iCallCount == 0 || s_iCallCount == CLIP_NUM_CALLS) winDebug ("winProcEstablishConnection - Hello\n"); - #endif - - /* Do nothing if clipboard is not enabled */ - if (!g_fClipboard) - { - winDebug ("winProcEstablishConnection - Clipboard is not enabled, " - "returning.\n"); - - /* Unwrap the original function, call it, and return */ - InitialVector[2] = winProcEstablishConnectionOrig; - iReturn = (*winProcEstablishConnectionOrig) (client); - winProcEstablishConnectionOrig = NULL; - return iReturn; - } - - /* Watch for server reset */ - if (s_ulServerGeneration != serverGeneration) - { - /* Save new generation number */ - s_ulServerGeneration = serverGeneration; - - /* Reset call count */ - s_iCallCount = 0; - } - - /* Increment call count */ - ++s_iCallCount; - - /* Wait for CLIP_NUM_CALLS when Xdmcp is enabled */ - if (g_fXdmcpEnabled - && !g_fClipboardLaunched - && s_iCallCount < CLIP_NUM_CALLS) - { - #ifdef WINDBG - if (s_iCallCount == 1) winDebug ("winProcEstablishConnection - Xdmcp, waiting to " - "start clipboard client until %dth call", CLIP_NUM_CALLS); - if (s_iCallCount == CLIP_NUM_CALLS - 1) winDebug (".\n"); - else winDebug ("."); - #endif - return (*winProcEstablishConnectionOrig) (client); - } - - /* - * This procedure is only used for initialization. - * We can unwrap the original procedure at this point - * so that this function is no longer called until the - * server resets and the function is wrapped again. - */ - InitialVector[2] = winProcEstablishConnectionOrig; - - /* - * Call original function and bail if it fails. - * NOTE: We must do this first, since we need XdmcpOpenDisplay - * to be called before we initialize our clipboard client. - */ - iReturn = (*winProcEstablishConnectionOrig) (client); - if (iReturn != 0) - { - ErrorF ("winProcEstablishConnection - ProcEstablishConnection " - "failed, bailing.\n"); - return iReturn; - } - - /* Clear original function pointer */ - winProcEstablishConnectionOrig = NULL; - - /* If the clipboard client has already been started, abort */ - if (g_fClipboardLaunched) - { - winDebug ("winProcEstablishConnection - Clipboard client already " - "launched, returning.\n"); - return iReturn; - } - - /* Startup the clipboard client if clipboard mode is being used */ - if (g_fClipboard) - { - /* - * NOTE: The clipboard client is started here for a reason: - * 1) Assume you are using XDMCP (e.g. XWin -query %hostname%) - * 2) If the clipboard client attaches during X Server startup, - * then it becomes the "magic client" that causes the X Server - * to reset if it exits. - * 3) XDMCP calls KillAllClients when it starts up. - * 4) The clipboard client is a client, so it is killed. - * 5) The clipboard client is the "magic client", so the X Server - * resets itself. - * 6) This repeats ad infinitum. - * 7) We avoid this by waiting until at least one client (could - * be XDM, could be another client) connects, which makes it - * almost certain that the clipboard client will not connect - * until after XDM when using XDMCP. - * 8) Unfortunately, there is another problem. - * 9) XDM walks the list of windows with XQueryTree, - * killing any client it finds with a window. - * 10)Thus, when using XDMCP we wait until CLIP_NUM_CALLS - * to ProcEstablishCeonnection before we startup the clipboard - * client. This should prevent XDM from finding the clipboard - * client, since it has not yet created a window. - */ - - /* Create the clipboard client thread */ - if (!winInitClipboard ()) - { - ErrorF ("winProcEstablishConnection - winClipboardInit " - "failed.\n"); - return iReturn; - } - - winDebug ("winProcEstablishConnection - winInitClipboard returned.\n"); - } - - /* Flag that clipboard client has been launched */ - g_fClipboardLaunched = TRUE; - - return iReturn; -} - - -/* - * Wrapper for internal SetSelectionOwner function. - * Grabs ownership of Windows clipboard when X11 clipboard owner changes. - */ -int -winProcSetSelectionOwner (ClientPtr client) -{ - int i; - DrawablePtr pDrawable; - WindowPtr pWindow = None; - static Window s_iOwners[CLIP_NUM_SELECTIONS] = {None}; - static unsigned long s_ulServerGeneration = 0; - REQUEST(xSetSelectionOwnerReq); - - REQUEST_SIZE_MATCH(xSetSelectionOwnerReq); - - winDebug ("winProcSetSelectionOwner - Hello.\n"); - - /* Watch for server reset */ - if (s_ulServerGeneration != serverGeneration) - { - /* Save new generation number */ - s_ulServerGeneration = serverGeneration; - - /* Initialize static variables */ - for (i = 0; i < CLIP_NUM_SELECTIONS; ++i) - s_iOwners[i] = None; - } - - /* Abort if clipboard not completely initialized yet */ - if (!g_fClipboardStarted) - { - winDebug ("winProcSetSelectionOwner - Clipboard not yet started, " - "aborting.\n"); - goto winProcSetSelectionOwner_Done; - } - - /* Grab window if we have one */ - if (None != stuff->window) - { - /* Grab the Window from the request */ - int rc = dixLookupWindow(&pWindow, stuff->window, client, DixReadAccess); - if (rc != Success) { - ErrorF ("winProcSetSelectionOwner - Found BadWindow, aborting.\n"); - goto winProcSetSelectionOwner_Done; - } - } - - /* Now we either have a valid window or None */ - - /* Save selection owners for monitored selections, ignore other selections */ - if (XA_PRIMARY == stuff->selection) - { - /* Look for owned -> not owned transition */ - if (None == stuff->window - && None != s_iOwners[CLIP_OWN_PRIMARY]) - { - winDebug ("winProcSetSelectionOwner - PRIMARY - Going from " - "owned to not owned.\n"); - - /* Adjust last owned selection */ - if (None != s_iOwners[CLIP_OWN_CLIPBOARD]) - g_atomLastOwnedSelection = MakeAtom ("CLIPBOARD", 9, TRUE); - else - g_atomLastOwnedSelection = None; - } - - /* Save new selection owner or None */ - s_iOwners[CLIP_OWN_PRIMARY] = stuff->window; - - winDebug ("winProcSetSelectionOwner - PRIMARY - Now owned by: 0x%x (clipboard is 0x%x)\n", - stuff->window,g_iClipboardWindow); - } - else if (MakeAtom ("CLIPBOARD", 9, TRUE) == stuff->selection) - { - /* Look for owned -> not owned transition */ - if (None == stuff->window - && None != s_iOwners[CLIP_OWN_CLIPBOARD]) - { - winDebug ("winProcSetSelectionOwner - CLIPBOARD - Going from " - "owned to not owned.\n"); - - /* Adjust last owned selection */ - if (None != s_iOwners[CLIP_OWN_PRIMARY]) - g_atomLastOwnedSelection = XA_PRIMARY; - else - g_atomLastOwnedSelection = None; - } - - /* Save new selection owner or None */ - s_iOwners[CLIP_OWN_CLIPBOARD] = stuff->window; - - winDebug ("winProcSetSelectionOwner - CLIPBOARD - Now owned by: 0x%x, clipboard is 0x%x\n", - stuff->window,g_iClipboardWindow); - } - else - goto winProcSetSelectionOwner_Done; - - /* - * At this point, if one of the selections is still owned by the - * clipboard manager then it should be marked as unowned since - * we will be taking ownership of the Win32 clipboard. - */ - if (g_iClipboardWindow == s_iOwners[CLIP_OWN_PRIMARY]) - s_iOwners[CLIP_OWN_PRIMARY] = None; - if (g_iClipboardWindow == s_iOwners[CLIP_OWN_CLIPBOARD]) - s_iOwners[CLIP_OWN_CLIPBOARD] = None; - - /* Abort if no window at this point */ - if (None == stuff->window) - { - winDebug ("winProcSetSelectionOwner - No window, returning.\n"); - goto winProcSetSelectionOwner_Done; - } - - /* Abort if invalid selection */ - if (!ValidAtom (stuff->selection)) - { - winDebug ("winProcSetSelectionOwner - Found BadAtom, aborting.\n"); - goto winProcSetSelectionOwner_Done; - } - - /* Cast Window to Drawable */ - pDrawable = (DrawablePtr) pWindow; - - /* Abort if clipboard manager is owning the selection */ - if (pDrawable->id == g_iClipboardWindow) - { - winDebug ("winProcSetSelectionOwner - We changed ownership, " - "aborting.\n"); - goto winProcSetSelectionOwner_Done; - } - - /* Abort if root window is taking ownership */ - if (pDrawable->id == 0) - { - winDebug ("winProcSetSelectionOwner - Root window taking ownership, " - "aborting\n"); - goto winProcSetSelectionOwner_Done; - } - - /* Access the Windows clipboard */ - if (!OpenClipboard (g_hwndClipboard)) - { - ErrorF ("winProcSetSelectionOwner - OpenClipboard () failed: %08x, hwnd: %08x\n", - (int) GetLastError (),g_hwndClipboard); - goto winProcSetSelectionOwner_Done; - } - - /* Take ownership of the Windows clipboard */ - if (!EmptyClipboard ()) - { - ErrorF ("winProcSetSelectionOwner - EmptyClipboard () failed: %08x\n", - (int) GetLastError ()); - CloseClipboard (); - goto winProcSetSelectionOwner_Done; - } - - winDebug("winProcSetSelectionOwner - SetClipboardData NULL\n"); - - /* Advertise Unicode if we support it */ - if (g_fUnicodeSupport) - SetClipboardData (CF_UNICODETEXT, NULL); - - /* Always advertise regular text */ - SetClipboardData (CF_TEXT, NULL); - - /* Save handle to last owned selection */ - g_atomLastOwnedSelection = stuff->selection; - - /* Release the clipboard */ - if (!CloseClipboard ()) - { - ErrorF ("winProcSetSelectionOwner - CloseClipboard () failed: " - "%08x\n", - (int) GetLastError ()); - goto winProcSetSelectionOwner_Done; - } - -winProcSetSelectionOwner_Done: - return (*winProcSetSelectionOwnerOrig) (client); -} +/*
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *Copyright (C) Colin Harrison 2005-2008
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the copyright holder(s)
+ *and author(s) shall not be used in advertising or otherwise to promote
+ *the sale, use or other dealings in this Software without prior written
+ *authorization from the copyright holder(s) and author(s).
+ *
+ * Authors: Harold L Hunt II
+ * Colin Harrison
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#include "dixstruct.h"
+#include <X11/Xatom.h>
+
+
+/*
+ * Constants
+ */
+
+#define CLIP_NUM_CALLS 4
+#define CLIP_NUM_SELECTIONS 2
+#define CLIP_OWN_PRIMARY 0
+#define CLIP_OWN_CLIPBOARD 1
+
+
+/*
+ * Local function prototypes
+ */
+
+DISPATCH_PROC(winProcEstablishConnection);
+DISPATCH_PROC(winProcQueryTree);
+DISPATCH_PROC(winProcSetSelectionOwner);
+
+
+/*
+ * References to external symbols
+ */
+
+extern Bool g_fUnicodeSupport;
+extern int g_iNumScreens;
+extern unsigned int g_uiAuthDataLen;
+extern char *g_pAuthData;
+extern Bool g_fXdmcpEnabled;
+extern Bool g_fClipboardLaunched;
+extern Bool g_fClipboardStarted;
+extern Bool g_fClipboard;
+extern Window g_iClipboardWindow;
+extern Atom g_atomLastOwnedSelection;
+extern HWND g_hwndClipboard;
+
+extern winDispatchProcPtr winProcEstablishConnectionOrig;
+extern winDispatchProcPtr winProcQueryTreeOrig;
+extern winDispatchProcPtr winProcSetSelectionOwnerOrig;
+
+
+/*
+ * Wrapper for internal QueryTree function.
+ * Hides the clipboard client when it is the only client remaining.
+ */
+
+int
+winProcQueryTree (ClientPtr client)
+{
+ int iReturn;
+
+ winDebug ("winProcQueryTree - Hello\n");
+
+ /*
+ * This procedure is only used for initialization.
+ * We can unwrap the original procedure at this point
+ * so that this function is no longer called until the
+ * server resets and the function is wrapped again.
+ */
+ ProcVector[X_QueryTree] = winProcQueryTreeOrig;
+
+ /*
+ * Call original function and bail if it fails.
+ * NOTE: We must do this first, since we need XdmcpOpenDisplay
+ * to be called before we initialize our clipboard client.
+ */
+ iReturn = (*winProcQueryTreeOrig) (client);
+ if (iReturn != 0)
+ {
+ ErrorF ("winProcQueryTree - ProcQueryTree failed, bailing.\n");
+ return iReturn;
+ }
+
+ /* Make errors more obvious */
+ winProcQueryTreeOrig = NULL;
+
+ /* Do nothing if clipboard is not enabled */
+ if (!g_fClipboard)
+ {
+ winDebug ("winProcQueryTree - Clipboard is not enabled, "
+ "returning.\n");
+ return iReturn;
+ }
+
+ /* If the clipboard client has already been started, abort */
+ if (g_fClipboardLaunched)
+ {
+ winDebug ("winProcQueryTree - Clipboard client already "
+ "launched, returning.\n");
+ return iReturn;
+ }
+
+ /* Startup the clipboard client if clipboard mode is being used */
+ if (g_fXdmcpEnabled && g_fClipboard)
+ {
+ /*
+ * NOTE: The clipboard client is started here for a reason:
+ * 1) Assume you are using XDMCP (e.g. XWin -query %hostname%)
+ * 2) If the clipboard client attaches during X Server startup,
+ * then it becomes the "magic client" that causes the X Server
+ * to reset if it exits.
+ * 3) XDMCP calls KillAllClients when it starts up.
+ * 4) The clipboard client is a client, so it is killed.
+ * 5) The clipboard client is the "magic client", so the X Server
+ * resets itself.
+ * 6) This repeats ad infinitum.
+ * 7) We avoid this by waiting until at least one client (could
+ * be XDM, could be another client) connects, which makes it
+ * almost certain that the clipboard client will not connect
+ * until after XDM when using XDMCP.
+ * 8) Unfortunately, there is another problem.
+ * 9) XDM walks the list of windows with XQueryTree,
+ * killing any client it finds with a window.
+ * 10)Thus, when using XDMCP we wait until the first call
+ * to ProcQueryTree before we startup the clipboard client.
+ * This should prevent XDM from finding the clipboard client,
+ * since it has not yet created a window.
+ * 11)Startup when not using XDMCP is handled in
+ * winProcEstablishConnection.
+ */
+
+ /* Create the clipboard client thread */
+ if (!winInitClipboard ())
+ {
+ ErrorF ("winProcQueryTree - winClipboardInit "
+ "failed.\n");
+ return iReturn;
+ }
+
+ winDebug ("winProcQueryTree - winInitClipboard returned.\n");
+ }
+
+ /* Flag that clipboard client has been launched */
+ g_fClipboardLaunched = TRUE;
+
+ return iReturn;
+}
+
+
+/*
+ * Wrapper for internal EstablishConnection function.
+ * Initializes internal clients that must not be started until
+ * an external client has connected.
+ */
+
+int
+winProcEstablishConnection (ClientPtr client)
+{
+ int iReturn;
+ static int s_iCallCount = 0;
+ static unsigned long s_ulServerGeneration = 0;
+
+ #ifdef WINDBG
+ if (s_iCallCount == 0 || s_iCallCount == CLIP_NUM_CALLS) winDebug ("winProcEstablishConnection - Hello\n");
+ #endif
+
+ /* Do nothing if clipboard is not enabled */
+ if (!g_fClipboard)
+ {
+ winDebug ("winProcEstablishConnection - Clipboard is not enabled, "
+ "returning.\n");
+
+ /* Unwrap the original function, call it, and return */
+ InitialVector[2] = winProcEstablishConnectionOrig;
+ iReturn = (*winProcEstablishConnectionOrig) (client);
+ winProcEstablishConnectionOrig = NULL;
+ return iReturn;
+ }
+
+ /* Watch for server reset */
+ if (s_ulServerGeneration != serverGeneration)
+ {
+ /* Save new generation number */
+ s_ulServerGeneration = serverGeneration;
+
+ /* Reset call count */
+ s_iCallCount = 0;
+ }
+
+ /* Increment call count */
+ ++s_iCallCount;
+
+ /* Wait for CLIP_NUM_CALLS when Xdmcp is enabled */
+ if (g_fXdmcpEnabled
+ && !g_fClipboardLaunched
+ && s_iCallCount < CLIP_NUM_CALLS)
+ {
+ #ifdef WINDBG
+ if (s_iCallCount == 1) winDebug ("winProcEstablishConnection - Xdmcp, waiting to "
+ "start clipboard client until %dth call", CLIP_NUM_CALLS);
+ if (s_iCallCount == CLIP_NUM_CALLS - 1) winDebug (".\n");
+ else winDebug (".");
+ #endif
+ return (*winProcEstablishConnectionOrig) (client);
+ }
+
+ /*
+ * This procedure is only used for initialization.
+ * We can unwrap the original procedure at this point
+ * so that this function is no longer called until the
+ * server resets and the function is wrapped again.
+ */
+ InitialVector[2] = winProcEstablishConnectionOrig;
+
+ /*
+ * Call original function and bail if it fails.
+ * NOTE: We must do this first, since we need XdmcpOpenDisplay
+ * to be called before we initialize our clipboard client.
+ */
+ iReturn = (*winProcEstablishConnectionOrig) (client);
+ if (iReturn != 0)
+ {
+ ErrorF ("winProcEstablishConnection - ProcEstablishConnection "
+ "failed, bailing.\n");
+ return iReturn;
+ }
+
+ /* Clear original function pointer */
+ winProcEstablishConnectionOrig = NULL;
+
+ /* If the clipboard client has already been started, abort */
+ if (g_fClipboardLaunched)
+ {
+ winDebug ("winProcEstablishConnection - Clipboard client already "
+ "launched, returning.\n");
+ return iReturn;
+ }
+
+ /* Startup the clipboard client if clipboard mode is being used */
+ if (g_fClipboard)
+ {
+ /*
+ * NOTE: The clipboard client is started here for a reason:
+ * 1) Assume you are using XDMCP (e.g. XWin -query %hostname%)
+ * 2) If the clipboard client attaches during X Server startup,
+ * then it becomes the "magic client" that causes the X Server
+ * to reset if it exits.
+ * 3) XDMCP calls KillAllClients when it starts up.
+ * 4) The clipboard client is a client, so it is killed.
+ * 5) The clipboard client is the "magic client", so the X Server
+ * resets itself.
+ * 6) This repeats ad infinitum.
+ * 7) We avoid this by waiting until at least one client (could
+ * be XDM, could be another client) connects, which makes it
+ * almost certain that the clipboard client will not connect
+ * until after XDM when using XDMCP.
+ * 8) Unfortunately, there is another problem.
+ * 9) XDM walks the list of windows with XQueryTree,
+ * killing any client it finds with a window.
+ * 10)Thus, when using XDMCP we wait until CLIP_NUM_CALLS
+ * to ProcEstablishCeonnection before we startup the clipboard
+ * client. This should prevent XDM from finding the clipboard
+ * client, since it has not yet created a window.
+ */
+
+ /* Create the clipboard client thread */
+ if (!winInitClipboard ())
+ {
+ ErrorF ("winProcEstablishConnection - winClipboardInit "
+ "failed.\n");
+ return iReturn;
+ }
+
+ winDebug ("winProcEstablishConnection - winInitClipboard returned.\n");
+ }
+
+ /* Flag that clipboard client has been launched */
+ g_fClipboardLaunched = TRUE;
+
+ return iReturn;
+}
+
+
+/*
+ * Wrapper for internal SetSelectionOwner function.
+ * Grabs ownership of Windows clipboard when X11 clipboard owner changes.
+ */
+int
+winProcSetSelectionOwner (ClientPtr client)
+{
+ int i;
+ DrawablePtr pDrawable;
+ WindowPtr pWindow = None;
+ static Window s_iOwners[CLIP_NUM_SELECTIONS] = {None};
+ static unsigned long s_ulServerGeneration = 0;
+ REQUEST(xSetSelectionOwnerReq);
+
+ REQUEST_SIZE_MATCH(xSetSelectionOwnerReq);
+
+ winDebug ("winProcSetSelectionOwner - Hello.\n");
+
+ /* Watch for server reset */
+ if (s_ulServerGeneration != serverGeneration)
+ {
+ /* Save new generation number */
+ s_ulServerGeneration = serverGeneration;
+
+ /* Initialize static variables */
+ for (i = 0; i < CLIP_NUM_SELECTIONS; ++i)
+ s_iOwners[i] = None;
+ }
+
+ /* Abort if clipboard not completely initialized yet */
+ if (!g_fClipboardStarted)
+ {
+ winDebug ("winProcSetSelectionOwner - Clipboard not yet started, "
+ "aborting.\n");
+ goto winProcSetSelectionOwner_Done;
+ }
+
+ /* Grab window if we have one */
+ if (None != stuff->window)
+ {
+ /* Grab the Window from the request */
+ int rc = dixLookupWindow(&pWindow, stuff->window, client, DixReadAccess);
+ if (rc != Success) {
+ ErrorF ("winProcSetSelectionOwner - Found BadWindow, aborting.\n");
+ goto winProcSetSelectionOwner_Done;
+ }
+ }
+
+ /* Now we either have a valid window or None */
+
+ /* Save selection owners for monitored selections, ignore other selections */
+ if (XA_PRIMARY == stuff->selection)
+ {
+ /* Look for owned -> not owned transition */
+ if (None == stuff->window
+ && None != s_iOwners[CLIP_OWN_PRIMARY])
+ {
+ winDebug ("winProcSetSelectionOwner - PRIMARY - Going from "
+ "owned to not owned.\n");
+
+ /* Adjust last owned selection */
+ if (None != s_iOwners[CLIP_OWN_CLIPBOARD])
+ g_atomLastOwnedSelection = MakeAtom ("CLIPBOARD", 9, TRUE);
+ else
+ g_atomLastOwnedSelection = None;
+ }
+
+ /* Save new selection owner or None */
+ s_iOwners[CLIP_OWN_PRIMARY] = stuff->window;
+
+ winDebug ("winProcSetSelectionOwner - PRIMARY - Now owned by: 0x%x (clipboard is 0x%x)\n",
+ stuff->window,g_iClipboardWindow);
+ }
+ else if (MakeAtom ("CLIPBOARD", 9, TRUE) == stuff->selection)
+ {
+ /* Look for owned -> not owned transition */
+ if (None == stuff->window
+ && None != s_iOwners[CLIP_OWN_CLIPBOARD])
+ {
+ winDebug ("winProcSetSelectionOwner - CLIPBOARD - Going from "
+ "owned to not owned.\n");
+
+ /* Adjust last owned selection */
+ if (None != s_iOwners[CLIP_OWN_PRIMARY])
+ g_atomLastOwnedSelection = XA_PRIMARY;
+ else
+ g_atomLastOwnedSelection = None;
+ }
+
+ /* Save new selection owner or None */
+ s_iOwners[CLIP_OWN_CLIPBOARD] = stuff->window;
+
+ winDebug ("winProcSetSelectionOwner - CLIPBOARD - Now owned by: 0x%x, clipboard is 0x%x\n",
+ stuff->window,g_iClipboardWindow);
+ }
+ else
+ goto winProcSetSelectionOwner_Done;
+
+ /*
+ * At this point, if one of the selections is still owned by the
+ * clipboard manager then it should be marked as unowned since
+ * we will be taking ownership of the Win32 clipboard.
+ */
+ if (g_iClipboardWindow == s_iOwners[CLIP_OWN_PRIMARY])
+ s_iOwners[CLIP_OWN_PRIMARY] = None;
+ if (g_iClipboardWindow == s_iOwners[CLIP_OWN_CLIPBOARD])
+ s_iOwners[CLIP_OWN_CLIPBOARD] = None;
+
+ /* Abort if no window at this point */
+ if (None == stuff->window)
+ {
+ winDebug ("winProcSetSelectionOwner - No window, returning.\n");
+ goto winProcSetSelectionOwner_Done;
+ }
+
+ /* Abort if invalid selection */
+ if (!ValidAtom (stuff->selection))
+ {
+ winDebug ("winProcSetSelectionOwner - Found BadAtom, aborting.\n");
+ goto winProcSetSelectionOwner_Done;
+ }
+
+ /* Cast Window to Drawable */
+ pDrawable = (DrawablePtr) pWindow;
+
+ /* Abort if clipboard manager is owning the selection */
+ if (pDrawable->id == g_iClipboardWindow)
+ {
+ winDebug ("winProcSetSelectionOwner - We changed ownership, "
+ "aborting.\n");
+ goto winProcSetSelectionOwner_Done;
+ }
+
+ /* Abort if root window is taking ownership */
+ if (pDrawable->id == 0)
+ {
+ winDebug ("winProcSetSelectionOwner - Root window taking ownership, "
+ "aborting\n");
+ goto winProcSetSelectionOwner_Done;
+ }
+
+ /* Access the Windows clipboard */
+ if (!OpenClipboard (g_hwndClipboard))
+ {
+ ErrorF ("winProcSetSelectionOwner - OpenClipboard () failed: %08x, hwnd: %08x\n",
+ (int) GetLastError (),g_hwndClipboard);
+ goto winProcSetSelectionOwner_Done;
+ }
+
+ /* Take ownership of the Windows clipboard */
+ if (!EmptyClipboard ())
+ {
+ ErrorF ("winProcSetSelectionOwner - EmptyClipboard () failed: %08x\n",
+ (int) GetLastError ());
+ CloseClipboard ();
+ goto winProcSetSelectionOwner_Done;
+ }
+
+ winDebug("winProcSetSelectionOwner - SetClipboardData NULL\n");
+
+ /* Advertise Unicode if we support it */
+ if (g_fUnicodeSupport)
+ SetClipboardData (CF_UNICODETEXT, NULL);
+
+ /* Always advertise regular text */
+ SetClipboardData (CF_TEXT, NULL);
+
+ /* Save handle to last owned selection */
+ g_atomLastOwnedSelection = stuff->selection;
+
+ /* Release the clipboard */
+ if (!CloseClipboard ())
+ {
+ ErrorF ("winProcSetSelectionOwner - CloseClipboard () failed: "
+ "%08x\n",
+ (int) GetLastError ());
+ goto winProcSetSelectionOwner_Done;
+ }
+
+winProcSetSelectionOwner_Done:
+ return (*winProcSetSelectionOwnerOrig) (client);
+}
diff --git a/xorg-server/hw/xwin/winclipboardxevents.c b/xorg-server/hw/xwin/winclipboardxevents.c index 09aec03fc..363b0f6fd 100644 --- a/xorg-server/hw/xwin/winclipboardxevents.c +++ b/xorg-server/hw/xwin/winclipboardxevents.c @@ -112,13 +112,12 @@ winClipboardFlushXEvents (HWND hwnd, #ifdef _DEBUG
{
char *pszAtomName = NULL;
-
- winDebug ("SelectionRequest - target %d\n",
- event.xselectionrequest.target);
-
+ winDebug("SelectionRequest - target %d\n",
+ event.xselectionrequest.target);
+
pszAtomName = XGetAtomName (pDisplay,
event.xselectionrequest.target);
- winDebug ("SelectionRequest - Target atom name %s\n", pszAtomName);
+ winDebug("SelectionRequest - Target atom name %s\n", pszAtomName);
XFree (pszAtomName);
pszAtomName = NULL;
winDebug ("SelectionRequest - owner %d\n", event.xselectionrequest.owner);
@@ -475,27 +474,6 @@ winClipboardFlushXEvents (HWND hwnd, /*
- * SelectionClear
- */
- case SelectionClear:
-#ifdef _DEBUG
- winDebug ("winClipboardFlushXEvents - SelectionClear\n");
- {
- char *pszAtomName;
-
- pszAtomName = XGetAtomName (pDisplay,
- event.xselection.selection);
-
- winDebug ("SelectionClear - ATOM: %s\n",
- pszAtomName);
- winDebug ("SelectionClear - owner %d\n", event.xselectionrequest.owner);
-
- XFree (pszAtomName);
- }
-#endif
- break;
-
- /*
* SelectionNotify
*/
case SelectionNotify:
@@ -503,14 +481,12 @@ winClipboardFlushXEvents (HWND hwnd, winDebug ("winClipboardFlushXEvents - SelectionNotify\n");
{
char *pszAtomName;
-
pszAtomName = XGetAtomName (pDisplay,
event.xselection.selection);
- winDebug ("SelectionNotify - ATOM: %s\n",
- pszAtomName);
+ winDebug("winClipboardFlushXEvents - SelectionNotify - ATOM: %s\n",
+ pszAtomName);
winDebug ("SelectionNotify - requestor %d\n", event.xselectionrequest.requestor);
-
XFree (pszAtomName);
}
#endif
@@ -524,27 +500,21 @@ winClipboardFlushXEvents (HWND hwnd, if (event.xselection.target == XA_STRING)
{
winDebug ("winClipboardFlushXEvents - SelectionNotify - "
- "XA_STRING\n");
+ "XA_STRING\n");
+
return WIN_XEVENTS_CONVERT;
}
else if (event.xselection.target == atomUTF8String)
{
- winDebug ("winClipboardFlushXEvents - SelectionNotify - "
- "Requesting conversion of UTF8 target.\n");
- iReturn = XConvertSelection (pDisplay,
- event.xselection.selection,
- XA_STRING,
- atomLocalProperty,
- iWindow,
- CurrentTime);
- if (iReturn != Success)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "XConvertSelection () failed for UTF8String, "
- "aborting: %d\n",
- iReturn);
- break;
- }
+ winDebug("winClipboardFlushXEvents - SelectionNotify - "
+ "Requesting conversion of UTF8 target.\n");
+
+ XConvertSelection (pDisplay,
+ event.xselection.selection,
+ XA_STRING,
+ atomLocalProperty,
+ iWindow,
+ CurrentTime);
/* Process the ConvertSelection event */
XFlush (pDisplay);
@@ -553,22 +523,15 @@ winClipboardFlushXEvents (HWND hwnd, #ifdef X_HAVE_UTF8_STRING
else if (event.xselection.target == atomCompoundText)
{
- winDebug ("winClipboardFlushXEvents - SelectionNotify - "
- "Requesting conversion of CompoundText target.\n");
- iReturn = XConvertSelection (pDisplay,
- event.xselection.selection,
- atomUTF8String,
- atomLocalProperty,
- iWindow,
- CurrentTime);
- if (iReturn != Success)
- {
- ErrorF ("winClipboardFlushXEvents - SelectionNotify - "
- "XConvertSelection () failed for CompoundText, "
- "aborting: %d\n",
- iReturn);
- break;
- }
+ winDebug("winClipboardFlushXEvents - SelectionNotify - "
+ "Requesting conversion of CompoundText target.\n");
+
+ XConvertSelection (pDisplay,
+ event.xselection.selection,
+ atomUTF8String,
+ atomLocalProperty,
+ iWindow,
+ CurrentTime);
/* Process the ConvertSelection event */
XFlush (pDisplay);
@@ -605,8 +568,8 @@ winClipboardFlushXEvents (HWND hwnd, break;
}
- winDebug ("SelectionNotify - returned data %d left %d\n",
- xtpText.nitems, ulReturnBytesLeft);
+ winDebug("SelectionNotify - returned data %d left %d\n",
+ xtpText.nitems, ulReturnBytesLeft);
/* Request the selection data */
iReturn = XGetWindowProperty (pDisplay,
@@ -633,11 +596,10 @@ winClipboardFlushXEvents (HWND hwnd, {
char *pszAtomName = NULL;
- winDebug ("SelectionNotify - returned data %d left %d\n",
- xtpText.nitems, ulReturnBytesLeft);
-
+ winDebug("SelectionNotify - returned data %d left %d\n",
+ xtpText.nitems, ulReturnBytesLeft);
pszAtomName = XGetAtomName(pDisplay, xtpText.encoding);
- winDebug ("Notify atom name %s\n", pszAtomName);
+ winDebug("Notify atom name %s\n", pszAtomName);
XFree (pszAtomName);
pszAtomName = NULL;
}
@@ -842,7 +804,32 @@ winClipboardFlushXEvents (HWND hwnd, SetClipboardData (CF_TEXT, NULL);
return WIN_XEVENTS_NOTIFY;
+ /*
+ * SelectionClear
+ */
+ case SelectionClear:
+#ifdef _DEBUG
+ winDebug ("SelectionClear - doing nothing\n");
+ {
+ char *pszAtomName;
+
+ pszAtomName = XGetAtomName (pDisplay,
+ event.xselection.selection);
+
+ winDebug ("SelectionClear - ATOM: %s\n",
+ pszAtomName);
+ winDebug ("SelectionClear - owner %d\n", event.xselectionrequest.owner);
+
+ XFree (pszAtomName);
+ }
+#endif
+ break;
+
+ case PropertyNotify:
+ break;
+
default:
+ ErrorF ("winClipboardFlushXEvents - unexpected event type %d\n", event.type);
break;
}
}
diff --git a/xorg-server/hw/xwin/wincmap.c b/xorg-server/hw/xwin/wincmap.c index c077f2235..370a4c584 100644 --- a/xorg-server/hw/xwin/wincmap.c +++ b/xorg-server/hw/xwin/wincmap.c @@ -1,622 +1,622 @@ -/* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of the XFree86 Project - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from the XFree86 Project. - * - * Authors: Dakshinamurthy Karra - * Suhaib M Siddiqi - * Peter Busch - * Harold L Hunt II - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" - - -/* - * Local prototypes - */ - -static int -winListInstalledColormaps (ScreenPtr pScreen, Colormap *pmaps); - -static void -winStoreColors (ColormapPtr pmap, int ndef, xColorItem *pdefs); - -static void -winInstallColormap (ColormapPtr pmap); - -static void -winUninstallColormap (ColormapPtr pmap); - -static void -winResolveColor (unsigned short *pred, - unsigned short *pgreen, - unsigned short *pblue, - VisualPtr pVisual); - -static Bool -winCreateColormap (ColormapPtr pmap); - -static void -winDestroyColormap (ColormapPtr pmap); - -static Bool -winGetPaletteDIB (ScreenPtr pScreen, ColormapPtr pcmap); - -static Bool -winGetPaletteDD (ScreenPtr pScreen, ColormapPtr pcmap); - - -/* - * Set screen functions for colormaps - */ - -void -winSetColormapFunctions (ScreenPtr pScreen) -{ - pScreen->CreateColormap = winCreateColormap; - pScreen->DestroyColormap = winDestroyColormap; - pScreen->InstallColormap = winInstallColormap; - pScreen->UninstallColormap = winUninstallColormap; - pScreen->ListInstalledColormaps = winListInstalledColormaps; - pScreen->StoreColors = winStoreColors; - pScreen->ResolveColor = winResolveColor; -} - - -/* See Porting Layer Definition - p. 30 */ -/* - * Walk the list of installed colormaps, filling the pmaps list - * with the resource ids of the installed maps, and return - * a count of the total number of installed maps. - */ -static int -winListInstalledColormaps (ScreenPtr pScreen, Colormap *pmaps) -{ - winScreenPriv(pScreen); - - /* - * There will only be one installed colormap, so we only need - * to return one id, and the count of installed maps will always - * be one. - */ - *pmaps = pScreenPriv->pcmapInstalled->mid; - return 1; -} - - -/* See Porting Layer Definition - p. 30 */ -/* See Programming Windows - p. 663 */ -static void -winInstallColormap (ColormapPtr pColormap) -{ - ScreenPtr pScreen = pColormap->pScreen; - winScreenPriv(pScreen); - ColormapPtr oldpmap = pScreenPriv->pcmapInstalled; - - winDebug ("winInstallColormap\n"); - - /* Did the colormap actually change? */ - if (pColormap != oldpmap) - { - winDebug ("winInstallColormap - Colormap has changed, attempt " - "to install.\n"); - - /* Was there a previous colormap? */ - if (oldpmap != (ColormapPtr) None) - { - /* There was a previous colormap; tell clients it is gone */ - WalkTree (pColormap->pScreen, TellLostMap, (char *)&oldpmap->mid); - } - - /* Install new colormap */ - pScreenPriv->pcmapInstalled = pColormap; - WalkTree (pColormap->pScreen, TellGainedMap, (char *)&pColormap->mid); - - /* Call the engine specific colormap install procedure */ - if (!((*pScreenPriv->pwinInstallColormap) (pColormap))) - { - ErrorF ("winInstallColormap - Screen specific colormap install " - "procedure failed. Continuing, but colors may be " - "messed up from now on.\n"); - } - } - - /* Save a pointer to the newly installed colormap */ - pScreenPriv->pcmapInstalled = pColormap; -} - - -/* See Porting Layer Definition - p. 30 */ -static void -winUninstallColormap (ColormapPtr pmap) -{ - winScreenPriv(pmap->pScreen); - ColormapPtr curpmap = pScreenPriv->pcmapInstalled; - - winDebug ("winUninstallColormap\n"); - - /* Is the colormap currently installed? */ - if (pmap != curpmap) - { - /* Colormap not installed, nothing to do */ - return; - } - - /* Clear the installed colormap flag */ - pScreenPriv->pcmapInstalled = NULL; - - /* - * NOTE: The default colormap does not get "uninstalled" before - * it is destroyed. - */ - - /* Install the default cmap in place of the cmap to be uninstalled */ - if (pmap->mid != pmap->pScreen->defColormap) - { - curpmap = (ColormapPtr) LookupIDByType(pmap->pScreen->defColormap, - RT_COLORMAP); - (*pmap->pScreen->InstallColormap) (curpmap); - } -} - - -/* See Porting Layer Definition - p. 30 */ -static void -winStoreColors (ColormapPtr pmap, - int ndef, - xColorItem *pdefs) -{ - ScreenPtr pScreen = pmap->pScreen; - winScreenPriv(pScreen); - winCmapPriv(pmap); - int i; - unsigned short nRed, nGreen, nBlue; - -#ifdef WINDBG - if (ndef != 1) - winDebug ("winStoreColors - ndef: %d\n", - ndef); -#endif - - /* Save the new colors in the colormap privates */ - for (i = 0; i < ndef; ++i) - { - /* Adjust the colors from the X color spec to the Windows color spec */ - nRed = pdefs[i].red >> 8; - nGreen = pdefs[i].green >> 8; - nBlue = pdefs[i].blue >> 8; - - /* Copy the colors to a palette entry table */ - pCmapPriv->peColors[pdefs[0].pixel + i].peRed = nRed; - pCmapPriv->peColors[pdefs[0].pixel + i].peGreen = nGreen; - pCmapPriv->peColors[pdefs[0].pixel + i].peBlue = nBlue; - - /* Copy the colors to a RGBQUAD table */ - pCmapPriv->rgbColors[pdefs[0].pixel + i].rgbRed = nRed; - pCmapPriv->rgbColors[pdefs[0].pixel + i].rgbGreen = nGreen; - pCmapPriv->rgbColors[pdefs[0].pixel + i].rgbBlue = nBlue; - - winDebug ("winStoreColors - nRed %d nGreen %d nBlue %d\n", - nRed, nGreen, nBlue); - } - - /* Call the engine specific store colors procedure */ - if (!((pScreenPriv->pwinStoreColors) (pmap, ndef, pdefs))) - { - ErrorF ("winStoreColors - Engine cpecific color storage procedure " - "failed. Continuing, but colors may be messed up from now " - "on.\n"); - } -} - - -/* See Porting Layer Definition - p. 30 */ -static void -winResolveColor (unsigned short *pred, - unsigned short *pgreen, - unsigned short *pblue, - VisualPtr pVisual) -{ - winDebug ("winResolveColor ()\n"); - - miResolveColor (pred, pgreen, pblue, pVisual); -} - - -/* See Porting Layer Definition - p. 29 */ -static Bool -winCreateColormap (ColormapPtr pmap) -{ - winPrivCmapPtr pCmapPriv = NULL; - ScreenPtr pScreen = pmap->pScreen; - winScreenPriv(pScreen); - - winDebug ("winCreateColormap\n"); - - /* Allocate colormap privates */ - if (!winAllocateCmapPrivates (pmap)) - { - ErrorF ("winCreateColorma - Couldn't allocate cmap privates\n"); - return FALSE; - } - - /* Get a pointer to the newly allocated privates */ - pCmapPriv = winGetCmapPriv (pmap); - - /* - * FIXME: This is some evil hackery to help in handling some X clients - * that expect the top pixel to be white. This "help" only lasts until - * some client overwrites the top colormap entry. - * - * We don't want to actually allocate the top entry, as that causes - * problems with X clients that need 7 planes (128 colors) in the default - * colormap, such as Magic 7.1. - */ - pCmapPriv->rgbColors[WIN_NUM_PALETTE_ENTRIES - 1].rgbRed = 255; - pCmapPriv->rgbColors[WIN_NUM_PALETTE_ENTRIES - 1].rgbGreen = 255; - pCmapPriv->rgbColors[WIN_NUM_PALETTE_ENTRIES - 1].rgbBlue = 255; - pCmapPriv->peColors[WIN_NUM_PALETTE_ENTRIES - 1].peRed = 255; - pCmapPriv->peColors[WIN_NUM_PALETTE_ENTRIES - 1].peGreen = 255; - pCmapPriv->peColors[WIN_NUM_PALETTE_ENTRIES - 1].peBlue = 255; - - /* Call the engine specific colormap initialization procedure */ - if (!((*pScreenPriv->pwinCreateColormap) (pmap))) - { - ErrorF ("winCreateColormap - Engine specific colormap creation " - "procedure failed. Aborting.\n"); - return FALSE; - } - - return TRUE; -} - - -/* See Porting Layer Definition - p. 29, 30 */ -static void -winDestroyColormap (ColormapPtr pColormap) -{ - winScreenPriv(pColormap->pScreen); - winCmapPriv(pColormap); - - /* Call the engine specific colormap destruction procedure */ - if (!((*pScreenPriv->pwinDestroyColormap) (pColormap))) - { - ErrorF ("winDestroyColormap - Engine specific colormap destruction " - "procedure failed. Continuing, but it is possible that memory " - "was leaked, or that colors will be messed up from now on.\n"); - } - - /* Free the colormap privates */ - free (pCmapPriv); - winSetCmapPriv (pColormap, NULL); - - winDebug ("winDestroyColormap - Returning\n"); -} - - -/* - * Internal function to load the palette used by the Shadow DIB - */ - -static Bool -winGetPaletteDIB (ScreenPtr pScreen, ColormapPtr pcmap) -{ - winScreenPriv(pScreen); - int i; - Pixel pixel; /* Pixel == CARD32 */ - CARD16 nRed, nGreen, nBlue; /* CARD16 == unsigned short */ - UINT uiColorsRetrieved = 0; - RGBQUAD rgbColors[WIN_NUM_PALETTE_ENTRIES]; - - /* Get the color table for the screen */ - uiColorsRetrieved = GetDIBColorTable (pScreenPriv->hdcScreen, - 0, - WIN_NUM_PALETTE_ENTRIES, - rgbColors); - if (uiColorsRetrieved == 0) - { - ErrorF ("winGetPaletteDIB - Could not retrieve screen color table\n"); - return FALSE; - } - - winDebug ("winGetPaletteDIB - Retrieved %d colors from DIB\n", - uiColorsRetrieved); - - /* Set the DIB color table to the default screen palette */ - if (SetDIBColorTable (pScreenPriv->hdcShadow, - 0, - uiColorsRetrieved, - rgbColors) == 0) - { - ErrorF ("winGetPaletteDIB - SetDIBColorTable () failed\n"); - return FALSE; - } - - /* Alloc each color in the DIB color table */ - for (i = 0; i < uiColorsRetrieved; ++i) - { - pixel = i; - - /* Extract the color values for current palette entry */ - nRed = rgbColors[i].rgbRed << 8; - nGreen = rgbColors[i].rgbGreen << 8; - nBlue = rgbColors[i].rgbBlue << 8; - - winDebug ("winGetPaletteDIB - Allocating a color: %d; " - "%d %d %d\n", - pixel, nRed, nGreen, nBlue); - - /* Allocate a entry in the X colormap */ - if (AllocColor (pcmap, - &nRed, - &nGreen, - &nBlue, - &pixel, - 0) != Success) - { - ErrorF ("winGetPaletteDIB - AllocColor () failed, pixel %d\n", - i); - return FALSE; - } - - if (i != pixel - || nRed != rgbColors[i].rgbRed - || nGreen != rgbColors[i].rgbGreen - || nBlue != rgbColors[i].rgbBlue) - { - winDebug ("winGetPaletteDIB - Got: %d; " - "%d %d %d\n", - (int) pixel, nRed, nGreen, nBlue); - } - - /* FIXME: Not sure that this bit is needed at all */ - pcmap->red[i].co.local.red = nRed; - pcmap->red[i].co.local.green = nGreen; - pcmap->red[i].co.local.blue = nBlue; - } - - /* System is using a colormap */ - /* Set the black and white pixel indices */ - pScreen->whitePixel = uiColorsRetrieved - 1; - pScreen->blackPixel = 0; - - return TRUE; -} - - -/* - * Internal function to load the standard system palette being used by DD - */ - -static Bool -winGetPaletteDD (ScreenPtr pScreen, ColormapPtr pcmap) -{ - int i; - Pixel pixel; /* Pixel == CARD32 */ - CARD16 nRed, nGreen, nBlue; /* CARD16 == unsigned short */ - UINT uiSystemPaletteEntries; - LPPALETTEENTRY ppeColors = NULL; - HDC hdc = NULL; - - /* Get a DC to obtain the default palette */ - hdc = GetDC (NULL); - if (hdc == NULL) - { - ErrorF ("winGetPaletteDD - Couldn't get a DC\n"); - return FALSE; - } - - /* Get the number of entries in the system palette */ - uiSystemPaletteEntries = GetSystemPaletteEntries (hdc, - 0, 0, NULL); - if (uiSystemPaletteEntries == 0) - { - ErrorF ("winGetPaletteDD - Unable to determine number of " - "system palette entries\n"); - return FALSE; - } - - winDebug ("winGetPaletteDD - uiSystemPaletteEntries %d\n", - uiSystemPaletteEntries); - - /* Allocate palette entries structure */ - ppeColors = malloc (uiSystemPaletteEntries * sizeof (PALETTEENTRY)); - if (ppeColors == NULL) - { - ErrorF ("winGetPaletteDD - malloc () for colormap failed\n"); - return FALSE; - } - - /* Get system palette entries */ - GetSystemPaletteEntries (hdc, - 0, uiSystemPaletteEntries, ppeColors); - - /* Allocate an X colormap entry for every system palette entry */ - for (i = 0; i < uiSystemPaletteEntries; ++i) - { - pixel = i; - - /* Extract the color values for current palette entry */ - nRed = ppeColors[i].peRed << 8; - nGreen = ppeColors[i].peGreen << 8; - nBlue = ppeColors[i].peBlue << 8; - winDebug ("winGetPaletteDD - Allocating a color: %d; " - "%d %d %d\n", - pixel, nRed, nGreen, nBlue); - if (AllocColor (pcmap, - &nRed, - &nGreen, - &nBlue, - &pixel, - 0) != Success) - { - ErrorF ("winGetPaletteDD - AllocColor () failed, pixel %d\n", - i); - free (ppeColors); - ppeColors = NULL; - return FALSE; - } - - pcmap->red[i].co.local.red = nRed; - pcmap->red[i].co.local.green = nGreen; - pcmap->red[i].co.local.blue = nBlue; - } - - /* System is using a colormap */ - /* Set the black and white pixel indices */ - pScreen->whitePixel = uiSystemPaletteEntries - 1; - pScreen->blackPixel = 0; - - /* Free colormap */ - if (ppeColors != NULL) - { - free (ppeColors); - ppeColors = NULL; - } - - /* Free the DC */ - if (hdc != NULL) - { - ReleaseDC (NULL, hdc); - hdc = NULL; - } - - return TRUE; -} - - -/* - * Install the standard fb colormap, or the GDI colormap, - * depending on the current screen depth. - */ - -Bool -winCreateDefColormap (ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - unsigned short zero = 0, ones = 0xFFFF; - VisualPtr pVisual = pScreenPriv->pRootVisual; - ColormapPtr pcmap = NULL; - Pixel wp, bp; - - winDebug ("winCreateDefColormap\n"); - - /* Use standard fb colormaps for non palettized color modes */ - if (pScreenInfo->dwBPP > 8) - { - winDebug ("winCreateDefColormap - Deferring to " \ - "fbCreateDefColormap ()\n"); - return fbCreateDefColormap (pScreen); - } - - /* - * AllocAll for non-Dynamic visual classes, - * AllocNone for Dynamic visual classes. - */ - - /* - * Dynamic visual classes allow the colors of the color map - * to be changed by clients. - */ - - winDebug ("winCreateDefColormap - defColormap: %d\n", - pScreen->defColormap); - - /* Allocate an X colormap, owned by client 0 */ - if (CreateColormap (pScreen->defColormap, - pScreen, - pVisual, - &pcmap, - (pVisual->class & DynamicClass) ? AllocNone : AllocAll, - 0) != Success) - { - ErrorF ("winCreateDefColormap - CreateColormap failed\n"); - return FALSE; - } - if (pcmap == NULL) - { - ErrorF ("winCreateDefColormap - Colormap could not be created\n"); - return FALSE; - } - - winDebug ("winCreateDefColormap - Created a colormap\n"); - - /* Branch on the visual class */ - if (!(pVisual->class & DynamicClass)) - { - /* Branch on engine type */ - if (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI) - { - /* Load the colors being used by the Shadow DIB */ - if (!winGetPaletteDIB (pScreen, pcmap)) - { - ErrorF ("winCreateDefColormap - Couldn't get DIB colors\n"); - return FALSE; - } - } - else - { - /* Load the colors from the default system palette */ - if (!winGetPaletteDD (pScreen, pcmap)) - { - ErrorF ("winCreateDefColormap - Couldn't get colors " - "for DD\n"); - return FALSE; - } - } - } - else - { - wp = pScreen->whitePixel; - bp = pScreen->blackPixel; - - /* Allocate a black and white pixel */ - if ((AllocColor (pcmap, &ones, &ones, &ones, &wp, 0) != - Success) - || - (AllocColor (pcmap, &zero, &zero, &zero, &bp, 0) != - Success)) - { - ErrorF ("winCreateDefColormap - Couldn't allocate bp or wp\n"); - return FALSE; - } - - pScreen->whitePixel = wp; - pScreen->blackPixel = bp; - - } - - /* Install the created colormap */ - (*pScreen->InstallColormap)(pcmap); - - winDebug ("winCreateDefColormap - Returning\n"); - - return TRUE; -} +/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Dakshinamurthy Karra
+ * Suhaib M Siddiqi
+ * Peter Busch
+ * Harold L Hunt II
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+
+
+/*
+ * Local prototypes
+ */
+
+static int
+winListInstalledColormaps (ScreenPtr pScreen, Colormap *pmaps);
+
+static void
+winStoreColors (ColormapPtr pmap, int ndef, xColorItem *pdefs);
+
+static void
+winInstallColormap (ColormapPtr pmap);
+
+static void
+winUninstallColormap (ColormapPtr pmap);
+
+static void
+winResolveColor (unsigned short *pred,
+ unsigned short *pgreen,
+ unsigned short *pblue,
+ VisualPtr pVisual);
+
+static Bool
+winCreateColormap (ColormapPtr pmap);
+
+static void
+winDestroyColormap (ColormapPtr pmap);
+
+static Bool
+winGetPaletteDIB (ScreenPtr pScreen, ColormapPtr pcmap);
+
+static Bool
+winGetPaletteDD (ScreenPtr pScreen, ColormapPtr pcmap);
+
+
+/*
+ * Set screen functions for colormaps
+ */
+
+void
+winSetColormapFunctions (ScreenPtr pScreen)
+{
+ pScreen->CreateColormap = winCreateColormap;
+ pScreen->DestroyColormap = winDestroyColormap;
+ pScreen->InstallColormap = winInstallColormap;
+ pScreen->UninstallColormap = winUninstallColormap;
+ pScreen->ListInstalledColormaps = winListInstalledColormaps;
+ pScreen->StoreColors = winStoreColors;
+ pScreen->ResolveColor = winResolveColor;
+}
+
+
+/* See Porting Layer Definition - p. 30 */
+/*
+ * Walk the list of installed colormaps, filling the pmaps list
+ * with the resource ids of the installed maps, and return
+ * a count of the total number of installed maps.
+ */
+static int
+winListInstalledColormaps (ScreenPtr pScreen, Colormap *pmaps)
+{
+ winScreenPriv(pScreen);
+
+ /*
+ * There will only be one installed colormap, so we only need
+ * to return one id, and the count of installed maps will always
+ * be one.
+ */
+ *pmaps = pScreenPriv->pcmapInstalled->mid;
+ return 1;
+}
+
+
+/* See Porting Layer Definition - p. 30 */
+/* See Programming Windows - p. 663 */
+static void
+winInstallColormap (ColormapPtr pColormap)
+{
+ ScreenPtr pScreen = pColormap->pScreen;
+ winScreenPriv(pScreen);
+ ColormapPtr oldpmap = pScreenPriv->pcmapInstalled;
+
+ winDebug ("winInstallColormap\n");
+
+ /* Did the colormap actually change? */
+ if (pColormap != oldpmap)
+ {
+ winDebug ("winInstallColormap - Colormap has changed, attempt "
+ "to install.\n");
+
+ /* Was there a previous colormap? */
+ if (oldpmap != (ColormapPtr) None)
+ {
+ /* There was a previous colormap; tell clients it is gone */
+ WalkTree (pColormap->pScreen, TellLostMap, (char *)&oldpmap->mid);
+ }
+
+ /* Install new colormap */
+ pScreenPriv->pcmapInstalled = pColormap;
+ WalkTree (pColormap->pScreen, TellGainedMap, (char *)&pColormap->mid);
+
+ /* Call the engine specific colormap install procedure */
+ if (!((*pScreenPriv->pwinInstallColormap) (pColormap)))
+ {
+ ErrorF ("winInstallColormap - Screen specific colormap install "
+ "procedure failed. Continuing, but colors may be "
+ "messed up from now on.\n");
+ }
+ }
+
+ /* Save a pointer to the newly installed colormap */
+ pScreenPriv->pcmapInstalled = pColormap;
+}
+
+
+/* See Porting Layer Definition - p. 30 */
+static void
+winUninstallColormap (ColormapPtr pmap)
+{
+ winScreenPriv(pmap->pScreen);
+ ColormapPtr curpmap = pScreenPriv->pcmapInstalled;
+
+ winDebug ("winUninstallColormap\n");
+
+ /* Is the colormap currently installed? */
+ if (pmap != curpmap)
+ {
+ /* Colormap not installed, nothing to do */
+ return;
+ }
+
+ /* Clear the installed colormap flag */
+ pScreenPriv->pcmapInstalled = NULL;
+
+ /*
+ * NOTE: The default colormap does not get "uninstalled" before
+ * it is destroyed.
+ */
+
+ /* Install the default cmap in place of the cmap to be uninstalled */
+ if (pmap->mid != pmap->pScreen->defColormap)
+ {
+ dixLookupResourceByType((pointer) &curpmap, pmap->pScreen->defColormap,
+ RT_COLORMAP, NullClient, DixUnknownAccess);
+ (*pmap->pScreen->InstallColormap) (curpmap);
+ }
+}
+
+
+/* See Porting Layer Definition - p. 30 */
+static void
+winStoreColors (ColormapPtr pmap,
+ int ndef,
+ xColorItem *pdefs)
+{
+ ScreenPtr pScreen = pmap->pScreen;
+ winScreenPriv(pScreen);
+ winCmapPriv(pmap);
+ int i;
+ unsigned short nRed, nGreen, nBlue;
+
+#ifdef WINDBG
+ if (ndef != 1)
+ winDebug ("winStoreColors - ndef: %d\n",
+ ndef);
+#endif
+
+ /* Save the new colors in the colormap privates */
+ for (i = 0; i < ndef; ++i)
+ {
+ /* Adjust the colors from the X color spec to the Windows color spec */
+ nRed = pdefs[i].red >> 8;
+ nGreen = pdefs[i].green >> 8;
+ nBlue = pdefs[i].blue >> 8;
+
+ /* Copy the colors to a palette entry table */
+ pCmapPriv->peColors[pdefs[0].pixel + i].peRed = nRed;
+ pCmapPriv->peColors[pdefs[0].pixel + i].peGreen = nGreen;
+ pCmapPriv->peColors[pdefs[0].pixel + i].peBlue = nBlue;
+
+ /* Copy the colors to a RGBQUAD table */
+ pCmapPriv->rgbColors[pdefs[0].pixel + i].rgbRed = nRed;
+ pCmapPriv->rgbColors[pdefs[0].pixel + i].rgbGreen = nGreen;
+ pCmapPriv->rgbColors[pdefs[0].pixel + i].rgbBlue = nBlue;
+
+ winDebug ("winStoreColors - nRed %d nGreen %d nBlue %d\n",
+ nRed, nGreen, nBlue);
+ }
+
+ /* Call the engine specific store colors procedure */
+ if (!((pScreenPriv->pwinStoreColors) (pmap, ndef, pdefs)))
+ {
+ ErrorF ("winStoreColors - Engine cpecific color storage procedure "
+ "failed. Continuing, but colors may be messed up from now "
+ "on.\n");
+ }
+}
+
+
+/* See Porting Layer Definition - p. 30 */
+static void
+winResolveColor (unsigned short *pred,
+ unsigned short *pgreen,
+ unsigned short *pblue,
+ VisualPtr pVisual)
+{
+ winDebug ("winResolveColor ()\n");
+
+ miResolveColor (pred, pgreen, pblue, pVisual);
+}
+
+
+/* See Porting Layer Definition - p. 29 */
+static Bool
+winCreateColormap (ColormapPtr pmap)
+{
+ winPrivCmapPtr pCmapPriv = NULL;
+ ScreenPtr pScreen = pmap->pScreen;
+ winScreenPriv(pScreen);
+
+ winDebug ("winCreateColormap\n");
+
+ /* Allocate colormap privates */
+ if (!winAllocateCmapPrivates (pmap))
+ {
+ ErrorF ("winCreateColorma - Couldn't allocate cmap privates\n");
+ return FALSE;
+ }
+
+ /* Get a pointer to the newly allocated privates */
+ pCmapPriv = winGetCmapPriv (pmap);
+
+ /*
+ * FIXME: This is some evil hackery to help in handling some X clients
+ * that expect the top pixel to be white. This "help" only lasts until
+ * some client overwrites the top colormap entry.
+ *
+ * We don't want to actually allocate the top entry, as that causes
+ * problems with X clients that need 7 planes (128 colors) in the default
+ * colormap, such as Magic 7.1.
+ */
+ pCmapPriv->rgbColors[WIN_NUM_PALETTE_ENTRIES - 1].rgbRed = 255;
+ pCmapPriv->rgbColors[WIN_NUM_PALETTE_ENTRIES - 1].rgbGreen = 255;
+ pCmapPriv->rgbColors[WIN_NUM_PALETTE_ENTRIES - 1].rgbBlue = 255;
+ pCmapPriv->peColors[WIN_NUM_PALETTE_ENTRIES - 1].peRed = 255;
+ pCmapPriv->peColors[WIN_NUM_PALETTE_ENTRIES - 1].peGreen = 255;
+ pCmapPriv->peColors[WIN_NUM_PALETTE_ENTRIES - 1].peBlue = 255;
+
+ /* Call the engine specific colormap initialization procedure */
+ if (!((*pScreenPriv->pwinCreateColormap) (pmap)))
+ {
+ ErrorF ("winCreateColormap - Engine specific colormap creation "
+ "procedure failed. Aborting.\n");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+/* See Porting Layer Definition - p. 29, 30 */
+static void
+winDestroyColormap (ColormapPtr pColormap)
+{
+ winScreenPriv(pColormap->pScreen);
+ winCmapPriv(pColormap);
+
+ /* Call the engine specific colormap destruction procedure */
+ if (!((*pScreenPriv->pwinDestroyColormap) (pColormap)))
+ {
+ ErrorF ("winDestroyColormap - Engine specific colormap destruction "
+ "procedure failed. Continuing, but it is possible that memory "
+ "was leaked, or that colors will be messed up from now on.\n");
+ }
+
+ /* Free the colormap privates */
+ free (pCmapPriv);
+ winSetCmapPriv (pColormap, NULL);
+
+ winDebug ("winDestroyColormap - Returning\n");
+}
+
+
+/*
+ * Internal function to load the palette used by the Shadow DIB
+ */
+
+static Bool
+winGetPaletteDIB (ScreenPtr pScreen, ColormapPtr pcmap)
+{
+ winScreenPriv(pScreen);
+ int i;
+ Pixel pixel; /* Pixel == CARD32 */
+ CARD16 nRed, nGreen, nBlue; /* CARD16 == unsigned short */
+ UINT uiColorsRetrieved = 0;
+ RGBQUAD rgbColors[WIN_NUM_PALETTE_ENTRIES];
+
+ /* Get the color table for the screen */
+ uiColorsRetrieved = GetDIBColorTable (pScreenPriv->hdcScreen,
+ 0,
+ WIN_NUM_PALETTE_ENTRIES,
+ rgbColors);
+ if (uiColorsRetrieved == 0)
+ {
+ ErrorF ("winGetPaletteDIB - Could not retrieve screen color table\n");
+ return FALSE;
+ }
+
+ winDebug ("winGetPaletteDIB - Retrieved %d colors from DIB\n",
+ uiColorsRetrieved);
+
+ /* Set the DIB color table to the default screen palette */
+ if (SetDIBColorTable (pScreenPriv->hdcShadow,
+ 0,
+ uiColorsRetrieved,
+ rgbColors) == 0)
+ {
+ ErrorF ("winGetPaletteDIB - SetDIBColorTable () failed\n");
+ return FALSE;
+ }
+
+ /* Alloc each color in the DIB color table */
+ for (i = 0; i < uiColorsRetrieved; ++i)
+ {
+ pixel = i;
+
+ /* Extract the color values for current palette entry */
+ nRed = rgbColors[i].rgbRed << 8;
+ nGreen = rgbColors[i].rgbGreen << 8;
+ nBlue = rgbColors[i].rgbBlue << 8;
+
+ winDebug ("winGetPaletteDIB - Allocating a color: %d; "
+ "%d %d %d\n",
+ pixel, nRed, nGreen, nBlue);
+
+ /* Allocate a entry in the X colormap */
+ if (AllocColor (pcmap,
+ &nRed,
+ &nGreen,
+ &nBlue,
+ &pixel,
+ 0) != Success)
+ {
+ ErrorF ("winGetPaletteDIB - AllocColor () failed, pixel %d\n",
+ i);
+ return FALSE;
+ }
+
+ if (i != pixel
+ || nRed != rgbColors[i].rgbRed
+ || nGreen != rgbColors[i].rgbGreen
+ || nBlue != rgbColors[i].rgbBlue)
+ {
+ winDebug ("winGetPaletteDIB - Got: %d; "
+ "%d %d %d\n",
+ (int) pixel, nRed, nGreen, nBlue);
+ }
+
+ /* FIXME: Not sure that this bit is needed at all */
+ pcmap->red[i].co.local.red = nRed;
+ pcmap->red[i].co.local.green = nGreen;
+ pcmap->red[i].co.local.blue = nBlue;
+ }
+
+ /* System is using a colormap */
+ /* Set the black and white pixel indices */
+ pScreen->whitePixel = uiColorsRetrieved - 1;
+ pScreen->blackPixel = 0;
+
+ return TRUE;
+}
+
+
+/*
+ * Internal function to load the standard system palette being used by DD
+ */
+
+static Bool
+winGetPaletteDD (ScreenPtr pScreen, ColormapPtr pcmap)
+{
+ int i;
+ Pixel pixel; /* Pixel == CARD32 */
+ CARD16 nRed, nGreen, nBlue; /* CARD16 == unsigned short */
+ UINT uiSystemPaletteEntries;
+ LPPALETTEENTRY ppeColors = NULL;
+ HDC hdc = NULL;
+
+ /* Get a DC to obtain the default palette */
+ hdc = GetDC (NULL);
+ if (hdc == NULL)
+ {
+ ErrorF ("winGetPaletteDD - Couldn't get a DC\n");
+ return FALSE;
+ }
+
+ /* Get the number of entries in the system palette */
+ uiSystemPaletteEntries = GetSystemPaletteEntries (hdc,
+ 0, 0, NULL);
+ if (uiSystemPaletteEntries == 0)
+ {
+ ErrorF ("winGetPaletteDD - Unable to determine number of "
+ "system palette entries\n");
+ return FALSE;
+ }
+
+ winDebug ("winGetPaletteDD - uiSystemPaletteEntries %d\n",
+ uiSystemPaletteEntries);
+
+ /* Allocate palette entries structure */
+ ppeColors = malloc (uiSystemPaletteEntries * sizeof (PALETTEENTRY));
+ if (ppeColors == NULL)
+ {
+ ErrorF ("winGetPaletteDD - malloc () for colormap failed\n");
+ return FALSE;
+ }
+
+ /* Get system palette entries */
+ GetSystemPaletteEntries (hdc,
+ 0, uiSystemPaletteEntries, ppeColors);
+
+ /* Allocate an X colormap entry for every system palette entry */
+ for (i = 0; i < uiSystemPaletteEntries; ++i)
+ {
+ pixel = i;
+
+ /* Extract the color values for current palette entry */
+ nRed = ppeColors[i].peRed << 8;
+ nGreen = ppeColors[i].peGreen << 8;
+ nBlue = ppeColors[i].peBlue << 8;
+ winDebug ("winGetPaletteDD - Allocating a color: %d; "
+ "%d %d %d\n",
+ pixel, nRed, nGreen, nBlue);
+ if (AllocColor (pcmap,
+ &nRed,
+ &nGreen,
+ &nBlue,
+ &pixel,
+ 0) != Success)
+ {
+ ErrorF ("winGetPaletteDD - AllocColor () failed, pixel %d\n",
+ i);
+ free (ppeColors);
+ ppeColors = NULL;
+ return FALSE;
+ }
+
+ pcmap->red[i].co.local.red = nRed;
+ pcmap->red[i].co.local.green = nGreen;
+ pcmap->red[i].co.local.blue = nBlue;
+ }
+
+ /* System is using a colormap */
+ /* Set the black and white pixel indices */
+ pScreen->whitePixel = uiSystemPaletteEntries - 1;
+ pScreen->blackPixel = 0;
+
+ /* Free colormap */
+ if (ppeColors != NULL)
+ {
+ free (ppeColors);
+ ppeColors = NULL;
+ }
+
+ /* Free the DC */
+ if (hdc != NULL)
+ {
+ ReleaseDC (NULL, hdc);
+ hdc = NULL;
+ }
+
+ return TRUE;
+}
+
+
+/*
+ * Install the standard fb colormap, or the GDI colormap,
+ * depending on the current screen depth.
+ */
+
+Bool
+winCreateDefColormap (ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ unsigned short zero = 0, ones = 0xFFFF;
+ VisualPtr pVisual = pScreenPriv->pRootVisual;
+ ColormapPtr pcmap = NULL;
+ Pixel wp, bp;
+
+ winDebug ("winCreateDefColormap\n");
+
+ /* Use standard fb colormaps for non palettized color modes */
+ if (pScreenInfo->dwBPP > 8)
+ {
+ winDebug ("winCreateDefColormap - Deferring to " \
+ "fbCreateDefColormap ()\n");
+ return fbCreateDefColormap (pScreen);
+ }
+
+ /*
+ * AllocAll for non-Dynamic visual classes,
+ * AllocNone for Dynamic visual classes.
+ */
+
+ /*
+ * Dynamic visual classes allow the colors of the color map
+ * to be changed by clients.
+ */
+
+ winDebug ("winCreateDefColormap - defColormap: %d\n",
+ pScreen->defColormap);
+
+ /* Allocate an X colormap, owned by client 0 */
+ if (CreateColormap (pScreen->defColormap,
+ pScreen,
+ pVisual,
+ &pcmap,
+ (pVisual->class & DynamicClass) ? AllocNone : AllocAll,
+ 0) != Success)
+ {
+ ErrorF ("winCreateDefColormap - CreateColormap failed\n");
+ return FALSE;
+ }
+ if (pcmap == NULL)
+ {
+ ErrorF ("winCreateDefColormap - Colormap could not be created\n");
+ return FALSE;
+ }
+
+ winDebug ("winCreateDefColormap - Created a colormap\n");
+
+ /* Branch on the visual class */
+ if (!(pVisual->class & DynamicClass))
+ {
+ /* Branch on engine type */
+ if (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI)
+ {
+ /* Load the colors being used by the Shadow DIB */
+ if (!winGetPaletteDIB (pScreen, pcmap))
+ {
+ ErrorF ("winCreateDefColormap - Couldn't get DIB colors\n");
+ return FALSE;
+ }
+ }
+ else
+ {
+ /* Load the colors from the default system palette */
+ if (!winGetPaletteDD (pScreen, pcmap))
+ {
+ ErrorF ("winCreateDefColormap - Couldn't get colors "
+ "for DD\n");
+ return FALSE;
+ }
+ }
+ }
+ else
+ {
+ wp = pScreen->whitePixel;
+ bp = pScreen->blackPixel;
+
+ /* Allocate a black and white pixel */
+ if ((AllocColor (pcmap, &ones, &ones, &ones, &wp, 0) !=
+ Success)
+ ||
+ (AllocColor (pcmap, &zero, &zero, &zero, &bp, 0) !=
+ Success))
+ {
+ ErrorF ("winCreateDefColormap - Couldn't allocate bp or wp\n");
+ return FALSE;
+ }
+
+ pScreen->whitePixel = wp;
+ pScreen->blackPixel = bp;
+
+ }
+
+ /* Install the created colormap */
+ (*pScreen->InstallColormap)(pcmap);
+
+ winDebug ("winCreateDefColormap - Returning\n");
+
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/windialogs.c b/xorg-server/hw/xwin/windialogs.c index 13b34353c..adbec19cb 100644 --- a/xorg-server/hw/xwin/windialogs.c +++ b/xorg-server/hw/xwin/windialogs.c @@ -1,778 +1,781 @@ -/* - *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of Harold L Hunt II - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from Harold L Hunt II. - * - * Authors: Harold L Hunt II - * Earle F. Philhower III - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" -#ifdef __CYGWIN__ -#include <sys/cygwin.h> -#endif -#include <shellapi.h> -#include "winprefs.h" - - -/* - * References to external globals - */ - -extern Bool g_fCursor; -extern HWND g_hDlgDepthChange; -extern HWND g_hDlgExit; -extern HWND g_hDlgAbout; -extern WINPREFS pref; -#ifdef XWIN_CLIPBOARD -extern Bool g_fClipboardStarted; -#endif -extern Bool g_fSoftwareCursor; - -#if defined(XWIN_MULTIWINDOW) -extern HICON g_hIconX; -extern HICON g_hSmallIconX; -#endif - -/* - * Local function prototypes - */ - -static wBOOL CALLBACK -winExitDlgProc (HWND hDialog, UINT message, - WPARAM wParam, LPARAM lParam); - -static wBOOL CALLBACK -winChangeDepthDlgProc (HWND hDialog, UINT message, - WPARAM wParam, LPARAM lParam); - -static wBOOL CALLBACK -winAboutDlgProc (HWND hDialog, UINT message, - WPARAM wParam, LPARAM lParam); - - -static void -winDrawURLWindow (LPARAM lParam); - -static LRESULT CALLBACK -winURLWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); - -static void -winOverrideURLButton (HWND hdlg, int id); - -static void -winUnoverrideURLButton (HWND hdlg, int id); - - -/* - * Owner-draw a button as a URL - */ - -static void -winDrawURLWindow (LPARAM lParam) -{ - DRAWITEMSTRUCT *draw; - char str[256]; - RECT rect; - HFONT font; - COLORREF crText; - - draw = (DRAWITEMSTRUCT *) lParam; - GetWindowText (draw->hwndItem, str, sizeof(str)); - str[255] = 0; - GetClientRect (draw->hwndItem, &rect); - - /* Color the button depending upon its state */ - if (draw->itemState & ODS_SELECTED) - crText = RGB(128+64,0,0); - else if (draw->itemState & ODS_FOCUS) - crText = RGB(0,128+64,0); - else - crText = RGB(0,0,128+64); - SetTextColor (draw->hDC, crText); - - /* Create font 8 high, standard dialog font */ - font = CreateFont (-8, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, - 0, 0, 0, 0, 0, "MS Sans Serif"); - if (!font) - { - ErrorF ("winDrawURLWindow: Unable to create URL font, bailing.\n"); - return; - } - /* Draw it */ - SetBkMode (draw->hDC, OPAQUE); - SelectObject (draw->hDC, font); - DrawText (draw->hDC, str, strlen (str),&rect,DT_CENTER | DT_VCENTER); - /* Delete the created font, replace it with stock font */ - DeleteObject (SelectObject (draw->hDC, GetStockObject (ANSI_VAR_FONT))); -} - - -/* - * WndProc for overridden buttons - */ - -static LRESULT CALLBACK -winURLWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - WNDPROC origCB = NULL; - HCURSOR cursor; - - /* If it's a SetCursor message, tell it to the hand */ - if (msg==WM_SETCURSOR) { - cursor = LoadCursor (NULL, IDC_HAND); - if (cursor) - SetCursor (cursor); - return TRUE; - } - origCB = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA); - /* Otherwise fall through to original WndProc */ - if (origCB) - return CallWindowProc (origCB, hwnd, msg, wParam, lParam); - else - return FALSE; -} - - -/* - * Register and unregister the custom WndProc - */ - -static void -winOverrideURLButton (HWND hwnd, int id) -{ - WNDPROC origCB; - origCB = (WNDPROC)SetWindowLongPtr(GetDlgItem (hwnd, id), - GWLP_WNDPROC, (LONG_PTR)winURLWndProc); - SetWindowLongPtr(GetDlgItem (hwnd, id), GWLP_USERDATA, (LONG_PTR)origCB); -} - -static void -winUnoverrideURLButton (HWND hwnd, int id) -{ - WNDPROC origCB; - origCB = (WNDPROC)SetWindowLongPtr(GetDlgItem (hwnd, id), - GWLP_USERDATA, 0); - if (origCB) - SetWindowLongPtr(GetDlgItem (hwnd, id), GWLP_WNDPROC, (LONG_PTR)origCB); -} - - -/* - * Center a dialog window in the desktop window - * and set small and large icons to X icons. - */ - -static void -winInitDialog (HWND hwndDlg) -{ - HWND hwndDesk; - RECT rc, rcDlg, rcDesk; - HICON hIcon, hIconSmall; - - hwndDesk = GetParent (hwndDlg); - if (!hwndDesk || IsIconic (hwndDesk)) - hwndDesk = GetDesktopWindow (); - - /* Remove minimize and maximize buttons */ - SetWindowLongPtr(hwndDlg, GWL_STYLE, - GetWindowLongPtr(hwndDlg, GWL_STYLE) - & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX)); - - /* Set Window not to show in the task bar */ - SetWindowLongPtr(hwndDlg, GWL_EXSTYLE, - GetWindowLongPtr(hwndDlg, GWL_EXSTYLE) & ~WS_EX_APPWINDOW ); - - /* Center dialog window in the screen. Not done for multi-monitor systems, where - * it is likely to end up split across the screens. In that case, it appears - * near the Tray icon. - */ - if (GetSystemMetrics(SM_CMONITORS)>1) { - /* Still need to refresh the frame change. */ - SetWindowPos (hwndDlg, HWND_TOP, 0,0,0,0, - SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); - } else { - GetWindowRect (hwndDesk, &rcDesk); - GetWindowRect (hwndDlg, &rcDlg); - CopyRect (&rc, &rcDesk); - - OffsetRect (&rcDlg, -rcDlg.left, -rcDlg.top); - OffsetRect (&rc, -rc.left, -rc.top); - OffsetRect (&rc, -rcDlg.right, -rcDlg.bottom); - - SetWindowPos (hwndDlg, - HWND_TOPMOST, - rcDesk.left + (rc.right / 2), - rcDesk.top + (rc.bottom / 2), - 0, 0, - SWP_NOSIZE | SWP_FRAMECHANGED); - } - -#ifdef XWIN_MULTIWINDOW - if (g_hIconX) hIcon=g_hIconX; - else -#endif - hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN)); - -#ifdef XWIN_MULTIWINDOW - if (g_hSmallIconX) hIconSmall=g_hSmallIconX; - else -#endif - hIconSmall = LoadImage (g_hInstance, - MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON, - GetSystemMetrics(SM_CXSMICON), - GetSystemMetrics(SM_CYSMICON), - LR_SHARED); - - PostMessage (hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon); - PostMessage (hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall); -} - - -int -GetLiveClients (winPrivScreenPtr pScreenPriv) -{ - int i; - int liveClients = 0; - - /* Count up running clients (clients[0] is serverClient) */ - for (i = 1; i < currentMaxClients; i++) - if (clients[i] != NullClient) - liveClients++; -#if defined(XWIN_MULTIWINDOW) - /* Count down server internal clients */ - if (pScreenPriv->pScreenInfo->fMultiWindow) - liveClients -= 2; /* multiwindow window manager & XMsgProc */ -#endif -#if defined(XWIN_CLIPBOARD) - if (g_fClipboardStarted) - liveClients--; /* clipboard manager */ -#endif - - /* A user reported that this sometimes drops below zero. just eye-candy. */ - if (liveClients < 0) - liveClients = 0; - - pScreenPriv->iConnectedClients = liveClients; - - return liveClients; -} - -/* - * Display the Exit dialog box - */ - -void -winDisplayExitDialog (winPrivScreenPtr pScreenPriv) -{ - int liveClients = GetLiveClients(pScreenPriv); - - /* Don't show the exit confirmation dialog if SilentExit is enabled */ - if (pref.fSilentExit && liveClients <= 0) - { - if (g_hDlgExit != NULL) - { - DestroyWindow (g_hDlgExit); - g_hDlgExit = NULL; - } - PostMessage (pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0); - return; - } - - /* Check if dialog already exists */ - if (g_hDlgExit != NULL) - { - /* Dialog box already exists, display it */ - ShowWindow (g_hDlgExit, SW_SHOWDEFAULT); - - /* User has lost the dialog. Show them where it is. */ - SetForegroundWindow (g_hDlgExit); - - return; - } - - /* Create dialog box */ - g_hDlgExit = CreateDialogParam (g_hInstance, - "EXIT_DIALOG", - pScreenPriv->hwndScreen, - winExitDlgProc, - (int) pScreenPriv); - - /* Show the dialog box */ - ShowWindow (g_hDlgExit, SW_SHOW); - - /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */ - SetForegroundWindow (g_hDlgExit); - - /* Set focus to the Cancel button */ - PostMessage (g_hDlgExit, WM_NEXTDLGCTL, - (WPARAM)GetDlgItem (g_hDlgExit, IDCANCEL), TRUE); -} - -#define CONNECTED_CLIENTS_FORMAT "There are currently %d clients connected." - - -/* - * Exit dialog window procedure - */ - -static wBOOL CALLBACK -winExitDlgProc (HWND hDialog, UINT message, - WPARAM wParam, LPARAM lParam) -{ - static winPrivScreenPtr s_pScreenPriv = NULL; - - /* Branch on message type */ - switch (message) - { - case WM_INITDIALOG: - { - char *pszConnectedClients; - - /* Store pointers to private structures for future use */ - s_pScreenPriv = (winPrivScreenPtr) lParam; - - winInitDialog (hDialog); - - /* Format the connected clients string */ - pszConnectedClients = Xprintf (CONNECTED_CLIENTS_FORMAT, - s_pScreenPriv->iConnectedClients); - if (!pszConnectedClients) - return TRUE; - - - - /* Set the number of connected clients */ - SetWindowText (GetDlgItem (hDialog, IDC_CLIENTS_CONNECTED), - pszConnectedClients); - xfree (pszConnectedClients); - } - return TRUE; - - case WM_COMMAND: - switch (LOWORD (wParam)) - { - case IDOK: - /* Send message to call the GiveUp function */ - PostMessage (s_pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0); - DestroyWindow (g_hDlgExit); - g_hDlgExit = NULL; - - /* Fix to make sure keyboard focus isn't trapped */ - PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0); - return TRUE; - - case IDCANCEL: - DestroyWindow (g_hDlgExit); - g_hDlgExit = NULL; - - /* Fix to make sure keyboard focus isn't trapped */ - PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0); - return TRUE; - } - break; - - case WM_MOUSEMOVE: - case WM_NCMOUSEMOVE: - /* Show the cursor if it is hidden */ - if (g_fSoftwareCursor && !g_fCursor) - { - g_fCursor = TRUE; - ShowCursor (TRUE); - } - return TRUE; - - case WM_CLOSE: - DestroyWindow (g_hDlgExit); - g_hDlgExit = NULL; - - /* Fix to make sure keyboard focus isn't trapped */ - PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0); - return TRUE; - } - - return FALSE; -} - - -/* - * Display the Depth Change dialog box - */ - -void -winDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv) -{ - /* Check if dialog already exists */ - if (g_hDlgDepthChange != NULL) - { - /* Dialog box already exists, display it */ - ShowWindow (g_hDlgDepthChange, SW_SHOWDEFAULT); - - /* User has lost the dialog. Show them where it is. */ - SetForegroundWindow (g_hDlgDepthChange); - - return; - } - - /* - * 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 (g_hInstance, - "DEPTH_CHANGE_BOX", - pScreenPriv->hwndScreen, - winChangeDepthDlgProc, - (int) pScreenPriv); - /* Show the dialog box */ - ShowWindow (g_hDlgDepthChange, SW_SHOW); - - winDebug ("winDisplayDepthChangeDialog - DialogBox returned: %d\n", - (int) g_hDlgDepthChange); - winDebug ("winDisplayDepthChangeDialog - GetLastError: %d\n", - (int) GetLastError ()); - - /* Minimize the display window */ - ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE); -} - - -/* - * Process messages for the dialog that is displayed for - * disruptive screen depth changes. - */ - -static wBOOL 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; - - winDebug ("winChangeDepthDlgProc\n"); - - /* Branch on message type */ - switch (message) - { - case WM_INITDIALOG: - winDebug ("winChangeDepthDlgProc - WM_INITDIALOG\n"); - - /* Store pointers to private structures for future use */ - s_pScreenPriv = (winPrivScreenPtr) lParam; - s_pScreenInfo = s_pScreenPriv->pScreenInfo; - s_pScreen = s_pScreenInfo->pScreen; - - winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - s_pScreenPriv: %08x, " - "s_pScreenInfo: %08x, s_pScreen: %08x\n", - s_pScreenPriv, s_pScreenInfo, s_pScreen); - - winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %d, " - "last bpp: %d\n", - s_pScreenInfo->dwBPP, - s_pScreenPriv->dwLastWindowsBitsPixel); - - winInitDialog( hwndDialog ); - - return TRUE; - - case WM_DISPLAYCHANGE: - winDebug ("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %d, " - "last bpp: %d, new bpp: %d\n", - s_pScreenInfo->dwBPP, - s_pScreenPriv->dwLastWindowsBitsPixel, - wParam); - - /* Dismiss the dialog if the display returns to the original depth */ - if (wParam == s_pScreenInfo->dwBPP) - { - winDebug ("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"); - - /* - * User dismissed the dialog, hide it until the - * display mode is restored. - */ - ShowWindow (g_hDlgDepthChange, SW_HIDE); - return TRUE; - } - break; - - case WM_CLOSE: - winDebug ("winChangeDepthDlgProc - WM_CLOSE\n"); - - DestroyWindow (g_hDlgAbout); - g_hDlgAbout = NULL; - - /* Fix to make sure keyboard focus isn't trapped */ - PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0); - return TRUE; - } - - return FALSE; -} - - -/* - * Display the About dialog box - */ - -void -winDisplayAboutDialog (winPrivScreenPtr pScreenPriv) -{ - /* Check if dialog already exists */ - if (g_hDlgAbout != NULL) - { - /* Dialog box already exists, display it */ - ShowWindow (g_hDlgAbout, SW_SHOWDEFAULT); - - /* User has lost the dialog. Show them where it is. */ - SetForegroundWindow (g_hDlgAbout); - - return; - } - - /* - * Display the about box - */ - g_hDlgAbout = CreateDialogParam (g_hInstance, - "ABOUT_BOX", - pScreenPriv->hwndScreen, - winAboutDlgProc, - (int) pScreenPriv); - - /* Show the dialog box */ - ShowWindow (g_hDlgAbout, SW_SHOW); - - /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */ - SetForegroundWindow (g_hDlgAbout); - - /* Set focus to the OK button */ - PostMessage (g_hDlgAbout, WM_NEXTDLGCTL, - (WPARAM)GetDlgItem (g_hDlgAbout, IDOK), TRUE); -} - - -/* - * Process messages for the about dialog. - */ - -static wBOOL CALLBACK -winAboutDlgProc (HWND hwndDialog, UINT message, - WPARAM wParam, LPARAM lParam) -{ - static winPrivScreenPtr s_pScreenPriv = NULL; - static winScreenInfo *s_pScreenInfo = NULL; - static ScreenPtr s_pScreen = NULL; - - winDebug ("winAboutDlgProc\n"); - - /* Branch on message type */ - switch (message) - { - case WM_INITDIALOG: - winDebug ("winAboutDlgProc - WM_INITDIALOG\n"); - - /* Store pointers to private structures for future use */ - s_pScreenPriv = (winPrivScreenPtr) lParam; - s_pScreenInfo = s_pScreenPriv->pScreenInfo; - s_pScreen = s_pScreenInfo->pScreen; - - winInitDialog (hwndDialog); - - /* Override the URL buttons */ - winOverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG); - winOverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE); - winOverrideURLButton (hwndDialog, ID_ABOUT_UG); - winOverrideURLButton (hwndDialog, ID_ABOUT_FAQ); - - return TRUE; - - case WM_DRAWITEM: - /* Draw the URL buttons as needed */ - winDrawURLWindow (lParam); - return TRUE; - - case WM_MOUSEMOVE: - case WM_NCMOUSEMOVE: - /* Show the cursor if it is hidden */ - if (g_fSoftwareCursor && !g_fCursor) - { - g_fCursor = TRUE; - ShowCursor (TRUE); - } - return TRUE; - - case WM_COMMAND: - switch (LOWORD (wParam)) - { - case IDOK: - case IDCANCEL: - winDebug ("winAboutDlgProc - WM_COMMAND - IDOK or IDCANCEL\n"); - - DestroyWindow (g_hDlgAbout); - g_hDlgAbout = NULL; - - /* Fix to make sure keyboard focus isn't trapped */ - PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0); - - /* Restore window procedures for URL buttons */ - winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG); - winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE); - winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG); - winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ); - - return TRUE; - - case ID_ABOUT_CHANGELOG: - { - int iReturn; -#ifdef __CYGWIN__ - const char * pszCygPath = "/usr/X11R6/share/doc/" - "xorg-x11-xwin/changelog.html"; - char pszWinPath[MAX_PATH + 1]; - - /* Convert the POSIX path to a Win32 path */ - cygwin_conv_to_win32_path (pszCygPath, pszWinPath); -#else - const char * pszWinPath = "http://x.cygwin.com/" - "devel/server/changelog.html"; -#endif - - iReturn = (int)ShellExecute (NULL, - "open", - pszWinPath, - NULL, - NULL, - SW_MAXIMIZE); - if (iReturn < 32) - { - ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_CHANGELOG - " - "ShellExecute failed: %d\n", - iReturn); - } - } - return TRUE; - - case ID_ABOUT_WEBSITE: - { - const char * pszPath = __VENDORDWEBSUPPORT__; - int iReturn; - - iReturn = (int)ShellExecute (NULL, - "open", - pszPath, - NULL, - NULL, - SW_MAXIMIZE); - if (iReturn < 32) - { - ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_WEBSITE - " - "ShellExecute failed: %d\n", - iReturn); - } - } - return TRUE; - - case ID_ABOUT_UG: - { - const char * pszPath = "http://x.cygwin.com/docs/ug/"; - int iReturn; - - iReturn = (int)ShellExecute (NULL, - "open", - pszPath, - NULL, - NULL, - SW_MAXIMIZE); - if (iReturn < 32) - { - ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_UG - " - "ShellExecute failed: %d\n", - iReturn); - } - } - return TRUE; - - case ID_ABOUT_FAQ: - { - const char * pszPath = "http://x.cygwin.com/docs/faq/"; - int iReturn; - - iReturn = (int)ShellExecute (NULL, - "open", - pszPath, - NULL, - NULL, - SW_MAXIMIZE); - if (iReturn < 32) - { - ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_FAQ - " - "ShellExecute failed: %d\n", - iReturn); - } - } - return TRUE; - } - break; - - case WM_CLOSE: - ErrorF ("winAboutDlgProc - WM_CLOSE\n"); - - DestroyWindow (g_hDlgAbout); - g_hDlgAbout = NULL; - - /* Fix to make sure keyboard focus isn't trapped */ - PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0); - - /* Restore window procedures for URL buttons */ - winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG); - winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE); - winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG); - winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ); - - return TRUE; - } - - return FALSE; -} +/*
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of Harold L Hunt II
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from Harold L Hunt II.
+ *
+ * Authors: Harold L Hunt II
+ * Earle F. Philhower III
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#ifdef __CYGWIN__
+#include <sys/cygwin.h>
+#endif
+#include <shellapi.h>
+#include "winprefs.h"
+
+
+/*
+ * References to external globals
+ */
+
+extern Bool g_fCursor;
+extern HWND g_hDlgDepthChange;
+extern HWND g_hDlgExit;
+extern HWND g_hDlgAbout;
+extern WINPREFS pref;
+#ifdef XWIN_CLIPBOARD
+extern Bool g_fClipboardStarted;
+#endif
+extern Bool g_fSoftwareCursor;
+
+#if defined(XWIN_MULTIWINDOW)
+extern HICON g_hIconX;
+extern HICON g_hSmallIconX;
+#endif
+
+/*
+ * Local function prototypes
+ */
+
+static wBOOL CALLBACK
+winExitDlgProc (HWND hDialog, UINT message,
+ WPARAM wParam, LPARAM lParam);
+
+static wBOOL CALLBACK
+winChangeDepthDlgProc (HWND hDialog, UINT message,
+ WPARAM wParam, LPARAM lParam);
+
+static wBOOL CALLBACK
+winAboutDlgProc (HWND hDialog, UINT message,
+ WPARAM wParam, LPARAM lParam);
+
+
+static void
+winDrawURLWindow (LPARAM lParam);
+
+static LRESULT CALLBACK
+winURLWndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
+
+static void
+winOverrideURLButton (HWND hdlg, int id);
+
+static void
+winUnoverrideURLButton (HWND hdlg, int id);
+
+
+/*
+ * Owner-draw a button as a URL
+ */
+
+static void
+winDrawURLWindow (LPARAM lParam)
+{
+ DRAWITEMSTRUCT *draw;
+ char str[256];
+ RECT rect;
+ HFONT font;
+ COLORREF crText;
+
+ draw = (DRAWITEMSTRUCT *) lParam;
+ GetWindowText (draw->hwndItem, str, sizeof(str));
+ str[255] = 0;
+ GetClientRect (draw->hwndItem, &rect);
+
+ /* Color the button depending upon its state */
+ if (draw->itemState & ODS_SELECTED)
+ crText = RGB(128+64,0,0);
+ else if (draw->itemState & ODS_FOCUS)
+ crText = RGB(0,128+64,0);
+ else
+ crText = RGB(0,0,128+64);
+ SetTextColor (draw->hDC, crText);
+
+ /* Create font 8 high, standard dialog font */
+ font = CreateFont (-8, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,
+ 0, 0, 0, 0, 0, "MS Sans Serif");
+ if (!font)
+ {
+ ErrorF ("winDrawURLWindow: Unable to create URL font, bailing.\n");
+ return;
+ }
+ /* Draw it */
+ SetBkMode (draw->hDC, OPAQUE);
+ SelectObject (draw->hDC, font);
+ DrawText (draw->hDC, str, strlen (str),&rect,DT_CENTER | DT_VCENTER);
+ /* Delete the created font, replace it with stock font */
+ DeleteObject (SelectObject (draw->hDC, GetStockObject (ANSI_VAR_FONT)));
+}
+
+
+/*
+ * WndProc for overridden buttons
+ */
+
+static LRESULT CALLBACK
+winURLWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ WNDPROC origCB = NULL;
+ HCURSOR cursor;
+
+ /* If it's a SetCursor message, tell it to the hand */
+ if (msg==WM_SETCURSOR) {
+ cursor = LoadCursor (NULL, IDC_HAND);
+ if (cursor)
+ SetCursor (cursor);
+ return TRUE;
+ }
+ origCB = (WNDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA);
+ /* Otherwise fall through to original WndProc */
+ if (origCB)
+ return CallWindowProc (origCB, hwnd, msg, wParam, lParam);
+ else
+ return FALSE;
+}
+
+
+/*
+ * Register and unregister the custom WndProc
+ */
+
+static void
+winOverrideURLButton (HWND hwnd, int id)
+{
+ WNDPROC origCB;
+ origCB = (WNDPROC)SetWindowLongPtr(GetDlgItem (hwnd, id),
+ GWLP_WNDPROC, (LONG_PTR)winURLWndProc);
+ SetWindowLongPtr(GetDlgItem (hwnd, id), GWLP_USERDATA, (LONG_PTR)origCB);
+}
+
+static void
+winUnoverrideURLButton (HWND hwnd, int id)
+{
+ WNDPROC origCB;
+ origCB = (WNDPROC)SetWindowLongPtr(GetDlgItem (hwnd, id),
+ GWLP_USERDATA, 0);
+ if (origCB)
+ SetWindowLongPtr(GetDlgItem (hwnd, id), GWLP_WNDPROC, (LONG_PTR)origCB);
+}
+
+
+/*
+ * Center a dialog window in the desktop window
+ * and set small and large icons to X icons.
+ */
+
+static void
+winInitDialog (HWND hwndDlg)
+{
+ HWND hwndDesk;
+ RECT rc, rcDlg, rcDesk;
+ HICON hIcon, hIconSmall;
+
+ hwndDesk = GetParent (hwndDlg);
+ if (!hwndDesk || IsIconic (hwndDesk))
+ hwndDesk = GetDesktopWindow ();
+
+ /* Remove minimize and maximize buttons */
+ SetWindowLongPtr(hwndDlg, GWL_STYLE,
+ GetWindowLongPtr(hwndDlg, GWL_STYLE)
+ & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX));
+
+ /* Set Window not to show in the task bar */
+ SetWindowLongPtr(hwndDlg, GWL_EXSTYLE,
+ GetWindowLongPtr(hwndDlg, GWL_EXSTYLE) & ~WS_EX_APPWINDOW );
+
+ /* Center dialog window in the screen. Not done for multi-monitor systems, where
+ * it is likely to end up split across the screens. In that case, it appears
+ * near the Tray icon.
+ */
+ if (GetSystemMetrics(SM_CMONITORS)>1) {
+ /* Still need to refresh the frame change. */
+ SetWindowPos (hwndDlg, HWND_TOP, 0,0,0,0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
+ } else {
+ GetWindowRect (hwndDesk, &rcDesk);
+ GetWindowRect (hwndDlg, &rcDlg);
+ CopyRect (&rc, &rcDesk);
+
+ OffsetRect (&rcDlg, -rcDlg.left, -rcDlg.top);
+ OffsetRect (&rc, -rc.left, -rc.top);
+ OffsetRect (&rc, -rcDlg.right, -rcDlg.bottom);
+
+ SetWindowPos (hwndDlg,
+ HWND_TOPMOST,
+ rcDesk.left + (rc.right / 2),
+ rcDesk.top + (rc.bottom / 2),
+ 0, 0,
+ SWP_NOSIZE | SWP_FRAMECHANGED);
+ }
+
+#ifdef XWIN_MULTIWINDOW
+ if (g_hIconX) hIcon=g_hIconX;
+ else
+#endif
+ hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
+
+#ifdef XWIN_MULTIWINDOW
+ if (g_hSmallIconX) hIconSmall=g_hSmallIconX;
+ else
+#endif
+ hIconSmall = LoadImage (g_hInstance,
+ MAKEINTRESOURCE(IDI_XWIN), IMAGE_ICON,
+ GetSystemMetrics(SM_CXSMICON),
+ GetSystemMetrics(SM_CYSMICON),
+ LR_SHARED);
+
+ PostMessage (hwndDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon);
+ PostMessage (hwndDlg, WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall);
+}
+
+
+int
+GetLiveClients (winPrivScreenPtr pScreenPriv)
+{
+ int i;
+ int liveClients = 0;
+
+ /* Count up running clients (clients[0] is serverClient) */
+ for (i = 1; i < currentMaxClients; i++)
+ if (clients[i] != NullClient)
+ liveClients++;
+#if defined(XWIN_MULTIWINDOW)
+ /* Count down server internal clients */
+ if (pScreenPriv->pScreenInfo->fMultiWindow)
+ liveClients -= 2; /* multiwindow window manager & XMsgProc */
+#endif
+#if defined(XWIN_CLIPBOARD)
+ if (g_fClipboardStarted)
+ liveClients--; /* clipboard manager */
+#endif
+
+ /* A user reported that this sometimes drops below zero. just eye-candy. */
+ if (liveClients < 0)
+ liveClients = 0;
+
+ pScreenPriv->iConnectedClients = liveClients;
+
+ return liveClients;
+}
+
+/*
+ * Display the Exit dialog box
+ */
+
+void
+winDisplayExitDialog (winPrivScreenPtr pScreenPriv)
+{
+ int liveClients = GetLiveClients(pScreenPriv);
+
+ /* Don't show the exit confirmation dialog if SilentExit & no clients,
+ or ForceExit, is enabled */
+ if ((pref.fSilentExit && liveClients <= 0) || pref.fForceExit)
+ {
+ if (g_hDlgExit != NULL)
+ {
+ DestroyWindow (g_hDlgExit);
+ g_hDlgExit = NULL;
+ }
+ PostMessage (pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
+ return;
+ }
+
+ /* Check if dialog already exists */
+ if (g_hDlgExit != NULL)
+ {
+ /* Dialog box already exists, display it */
+ ShowWindow (g_hDlgExit, SW_SHOWDEFAULT);
+
+ /* User has lost the dialog. Show them where it is. */
+ SetForegroundWindow (g_hDlgExit);
+
+ return;
+ }
+
+ /* Create dialog box */
+ g_hDlgExit = CreateDialogParam (g_hInstance,
+ "EXIT_DIALOG",
+ pScreenPriv->hwndScreen,
+ winExitDlgProc,
+ (int) pScreenPriv);
+
+ /* Show the dialog box */
+ ShowWindow (g_hDlgExit, SW_SHOW);
+
+ /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */
+ SetForegroundWindow (g_hDlgExit);
+
+ /* Set focus to the Cancel button */
+ PostMessage (g_hDlgExit, WM_NEXTDLGCTL,
+ (WPARAM)GetDlgItem (g_hDlgExit, IDCANCEL), TRUE);
+}
+
+#define CONNECTED_CLIENTS_FORMAT "There %s currently %d client%s connected."
+
+
+/*
+ * Exit dialog window procedure
+ */
+
+static wBOOL CALLBACK
+winExitDlgProc (HWND hDialog, UINT message,
+ WPARAM wParam, LPARAM lParam)
+{
+ static winPrivScreenPtr s_pScreenPriv = NULL;
+
+ /* Branch on message type */
+ switch (message)
+ {
+ case WM_INITDIALOG:
+ {
+ char *pszConnectedClients;
+
+ /* Store pointers to private structures for future use */
+ s_pScreenPriv = (winPrivScreenPtr) lParam;
+
+ winInitDialog (hDialog);
+
+ /* Format the connected clients string */
+ pszConnectedClients = Xprintf (CONNECTED_CLIENTS_FORMAT,
+ (s_pScreenPriv->iConnectedClients == 1) ? "is" : "are",
+ s_pScreenPriv->iConnectedClients,
+ (s_pScreenPriv->iConnectedClients == 1) ? "" : "s");
+ if (!pszConnectedClients)
+ return TRUE;
+
+
+
+ /* Set the number of connected clients */
+ SetWindowText (GetDlgItem (hDialog, IDC_CLIENTS_CONNECTED),
+ pszConnectedClients);
+ xfree (pszConnectedClients);
+ }
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD (wParam))
+ {
+ case IDOK:
+ /* Send message to call the GiveUp function */
+ PostMessage (s_pScreenPriv->hwndScreen, WM_GIVEUP, 0, 0);
+ DestroyWindow (g_hDlgExit);
+ g_hDlgExit = NULL;
+
+ /* Fix to make sure keyboard focus isn't trapped */
+ PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
+ return TRUE;
+
+ case IDCANCEL:
+ DestroyWindow (g_hDlgExit);
+ g_hDlgExit = NULL;
+
+ /* Fix to make sure keyboard focus isn't trapped */
+ PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
+ return TRUE;
+ }
+ break;
+
+ case WM_MOUSEMOVE:
+ case WM_NCMOUSEMOVE:
+ /* Show the cursor if it is hidden */
+ if (g_fSoftwareCursor && !g_fCursor)
+ {
+ g_fCursor = TRUE;
+ ShowCursor (TRUE);
+ }
+ return TRUE;
+
+ case WM_CLOSE:
+ DestroyWindow (g_hDlgExit);
+ g_hDlgExit = NULL;
+
+ /* Fix to make sure keyboard focus isn't trapped */
+ PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+/*
+ * Display the Depth Change dialog box
+ */
+
+void
+winDisplayDepthChangeDialog (winPrivScreenPtr pScreenPriv)
+{
+ /* Check if dialog already exists */
+ if (g_hDlgDepthChange != NULL)
+ {
+ /* Dialog box already exists, display it */
+ ShowWindow (g_hDlgDepthChange, SW_SHOWDEFAULT);
+
+ /* User has lost the dialog. Show them where it is. */
+ SetForegroundWindow (g_hDlgDepthChange);
+
+ return;
+ }
+
+ /*
+ * 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 (g_hInstance,
+ "DEPTH_CHANGE_BOX",
+ pScreenPriv->hwndScreen,
+ winChangeDepthDlgProc,
+ (int) pScreenPriv);
+ /* Show the dialog box */
+ ShowWindow (g_hDlgDepthChange, SW_SHOW);
+
+ winDebug ("winDisplayDepthChangeDialog - DialogBox returned: %d\n",
+ (int) g_hDlgDepthChange);
+ winDebug ("winDisplayDepthChangeDialog - GetLastError: %d\n",
+ (int) GetLastError ());
+
+ /* Minimize the display window */
+ ShowWindow (pScreenPriv->hwndScreen, SW_MINIMIZE);
+}
+
+
+/*
+ * Process messages for the dialog that is displayed for
+ * disruptive screen depth changes.
+ */
+
+static wBOOL 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;
+
+ winDebug ("winChangeDepthDlgProc\n");
+
+ /* Branch on message type */
+ switch (message)
+ {
+ case WM_INITDIALOG:
+ winDebug ("winChangeDepthDlgProc - WM_INITDIALOG\n");
+
+ /* Store pointers to private structures for future use */
+ s_pScreenPriv = (winPrivScreenPtr) lParam;
+ s_pScreenInfo = s_pScreenPriv->pScreenInfo;
+ s_pScreen = s_pScreenInfo->pScreen;
+
+ winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - s_pScreenPriv: %08x, "
+ "s_pScreenInfo: %08x, s_pScreen: %08x\n",
+ s_pScreenPriv, s_pScreenInfo, s_pScreen);
+
+ winDebug ("winChangeDepthDlgProc - WM_INITDIALOG - orig bpp: %d, "
+ "last bpp: %d\n",
+ s_pScreenInfo->dwBPP,
+ s_pScreenPriv->dwLastWindowsBitsPixel);
+
+ winInitDialog( hwndDialog );
+
+ return TRUE;
+
+ case WM_DISPLAYCHANGE:
+ winDebug ("winChangeDepthDlgProc - WM_DISPLAYCHANGE - orig bpp: %d, "
+ "last bpp: %d, new bpp: %d\n",
+ s_pScreenInfo->dwBPP,
+ s_pScreenPriv->dwLastWindowsBitsPixel,
+ wParam);
+
+ /* Dismiss the dialog if the display returns to the original depth */
+ if (wParam == s_pScreenInfo->dwBPP)
+ {
+ winDebug ("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");
+
+ /*
+ * User dismissed the dialog, hide it until the
+ * display mode is restored.
+ */
+ ShowWindow (g_hDlgDepthChange, SW_HIDE);
+ return TRUE;
+ }
+ break;
+
+ case WM_CLOSE:
+ winDebug ("winChangeDepthDlgProc - WM_CLOSE\n");
+
+ DestroyWindow (g_hDlgAbout);
+ g_hDlgAbout = NULL;
+
+ /* Fix to make sure keyboard focus isn't trapped */
+ PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
+/*
+ * Display the About dialog box
+ */
+
+void
+winDisplayAboutDialog (winPrivScreenPtr pScreenPriv)
+{
+ /* Check if dialog already exists */
+ if (g_hDlgAbout != NULL)
+ {
+ /* Dialog box already exists, display it */
+ ShowWindow (g_hDlgAbout, SW_SHOWDEFAULT);
+
+ /* User has lost the dialog. Show them where it is. */
+ SetForegroundWindow (g_hDlgAbout);
+
+ return;
+ }
+
+ /*
+ * Display the about box
+ */
+ g_hDlgAbout = CreateDialogParam (g_hInstance,
+ "ABOUT_BOX",
+ pScreenPriv->hwndScreen,
+ winAboutDlgProc,
+ (int) pScreenPriv);
+
+ /* Show the dialog box */
+ ShowWindow (g_hDlgAbout, SW_SHOW);
+
+ /* Needed to get keyboard controls (tab, arrows, enter, esc) to work */
+ SetForegroundWindow (g_hDlgAbout);
+
+ /* Set focus to the OK button */
+ PostMessage (g_hDlgAbout, WM_NEXTDLGCTL,
+ (WPARAM)GetDlgItem (g_hDlgAbout, IDOK), TRUE);
+}
+
+
+/*
+ * Process messages for the about dialog.
+ */
+
+static wBOOL CALLBACK
+winAboutDlgProc (HWND hwndDialog, UINT message,
+ WPARAM wParam, LPARAM lParam)
+{
+ static winPrivScreenPtr s_pScreenPriv = NULL;
+ static winScreenInfo *s_pScreenInfo = NULL;
+ static ScreenPtr s_pScreen = NULL;
+
+ winDebug ("winAboutDlgProc\n");
+
+ /* Branch on message type */
+ switch (message)
+ {
+ case WM_INITDIALOG:
+ winDebug ("winAboutDlgProc - WM_INITDIALOG\n");
+
+ /* Store pointers to private structures for future use */
+ s_pScreenPriv = (winPrivScreenPtr) lParam;
+ s_pScreenInfo = s_pScreenPriv->pScreenInfo;
+ s_pScreen = s_pScreenInfo->pScreen;
+
+ winInitDialog (hwndDialog);
+
+ /* Override the URL buttons */
+ winOverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
+ winOverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
+ winOverrideURLButton (hwndDialog, ID_ABOUT_UG);
+ winOverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
+
+ return TRUE;
+
+ case WM_DRAWITEM:
+ /* Draw the URL buttons as needed */
+ winDrawURLWindow (lParam);
+ return TRUE;
+
+ case WM_MOUSEMOVE:
+ case WM_NCMOUSEMOVE:
+ /* Show the cursor if it is hidden */
+ if (g_fSoftwareCursor && !g_fCursor)
+ {
+ g_fCursor = TRUE;
+ ShowCursor (TRUE);
+ }
+ return TRUE;
+
+ case WM_COMMAND:
+ switch (LOWORD (wParam))
+ {
+ case IDOK:
+ case IDCANCEL:
+ winDebug ("winAboutDlgProc - WM_COMMAND - IDOK or IDCANCEL\n");
+
+ DestroyWindow (g_hDlgAbout);
+ g_hDlgAbout = NULL;
+
+ /* Fix to make sure keyboard focus isn't trapped */
+ PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
+
+ /* Restore window procedures for URL buttons */
+ winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
+ winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
+ winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG);
+ winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
+
+ return TRUE;
+
+ case ID_ABOUT_CHANGELOG:
+ {
+ int iReturn;
+#ifdef __CYGWIN__
+ const char * pszCygPath = "/usr/X11R6/share/doc/"
+ "xorg-x11-xwin/changelog.html";
+ char pszWinPath[MAX_PATH + 1];
+
+ /* Convert the POSIX path to a Win32 path */
+ cygwin_conv_to_win32_path (pszCygPath, pszWinPath);
+#else
+ const char * pszWinPath = "http://x.cygwin.com/"
+ "devel/server/changelog.html";
+#endif
+
+ iReturn = (int)ShellExecute (NULL,
+ "open",
+ pszWinPath,
+ NULL,
+ NULL,
+ SW_MAXIMIZE);
+ if (iReturn < 32)
+ {
+ ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_CHANGELOG - "
+ "ShellExecute failed: %d\n",
+ iReturn);
+ }
+ }
+ return TRUE;
+
+ case ID_ABOUT_WEBSITE:
+ {
+ const char * pszPath = __VENDORDWEBSUPPORT__;
+ int iReturn;
+
+ iReturn = (int)ShellExecute (NULL,
+ "open",
+ pszPath,
+ NULL,
+ NULL,
+ SW_MAXIMIZE);
+ if (iReturn < 32)
+ {
+ ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_WEBSITE - "
+ "ShellExecute failed: %d\n",
+ iReturn);
+ }
+ }
+ return TRUE;
+
+ case ID_ABOUT_UG:
+ {
+ const char * pszPath = "http://x.cygwin.com/docs/ug/";
+ int iReturn;
+
+ iReturn = (int)ShellExecute (NULL,
+ "open",
+ pszPath,
+ NULL,
+ NULL,
+ SW_MAXIMIZE);
+ if (iReturn < 32)
+ {
+ ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_UG - "
+ "ShellExecute failed: %d\n",
+ iReturn);
+ }
+ }
+ return TRUE;
+
+ case ID_ABOUT_FAQ:
+ {
+ const char * pszPath = "http://x.cygwin.com/docs/faq/";
+ int iReturn;
+
+ iReturn = (int)ShellExecute (NULL,
+ "open",
+ pszPath,
+ NULL,
+ NULL,
+ SW_MAXIMIZE);
+ if (iReturn < 32)
+ {
+ ErrorF ("winAboutDlgProc - WM_COMMAND - ID_ABOUT_FAQ - "
+ "ShellExecute failed: %d\n",
+ iReturn);
+ }
+ }
+ return TRUE;
+ }
+ break;
+
+ case WM_CLOSE:
+ ErrorF ("winAboutDlgProc - WM_CLOSE\n");
+
+ DestroyWindow (g_hDlgAbout);
+ g_hDlgAbout = NULL;
+
+ /* Fix to make sure keyboard focus isn't trapped */
+ PostMessage (s_pScreenPriv->hwndScreen, WM_NULL, 0, 0);
+
+ /* Restore window procedures for URL buttons */
+ winUnoverrideURLButton (hwndDialog, ID_ABOUT_CHANGELOG);
+ winUnoverrideURLButton (hwndDialog, ID_ABOUT_WEBSITE);
+ winUnoverrideURLButton (hwndDialog, ID_ABOUT_UG);
+ winUnoverrideURLButton (hwndDialog, ID_ABOUT_FAQ);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
diff --git a/xorg-server/hw/xwin/winglobals.c b/xorg-server/hw/xwin/winglobals.c index 280761e72..71a0e6a7e 100644 --- a/xorg-server/hw/xwin/winglobals.c +++ b/xorg-server/hw/xwin/winglobals.c @@ -1,146 +1,146 @@ -/* - *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved. - *Copyright (C) Colin Harrison 2005-2008 - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of Harold L Hunt II - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from Harold L Hunt II. - * - * Authors: Harold L Hunt II - * Colin Harrison - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" - - -/* - * General global variables - */ - -int g_iNumScreens = 0; -winScreenInfo g_ScreenInfo[MAXSCREENS]; -int g_iLastScreen = -1; -#ifdef HAS_DEVWINDOWS -int g_fdMessageQueue = WIN_FD_INVALID; -#endif -static int g_iScreenPrivateKeyIndex; -DevPrivateKey g_iScreenPrivateKey = &g_iScreenPrivateKeyIndex; -static int g_iCmapPrivateKeyIndex; -DevPrivateKey g_iCmapPrivateKey = &g_iCmapPrivateKeyIndex; -static int g_iGCPrivateKeyIndex; -DevPrivateKey g_iGCPrivateKey = &g_iGCPrivateKeyIndex; -static int g_iPixmapPrivateKeyIndex; -DevPrivateKey g_iPixmapPrivateKey = &g_iPixmapPrivateKeyIndex; -static int g_iWindowPrivateKeyIndex; -DevPrivateKey g_iWindowPrivateKey = &g_iWindowPrivateKeyIndex; -unsigned long g_ulServerGeneration = 0; -Bool g_fInitializedDefaultScreens = FALSE; -DWORD g_dwEnginesSupported = 0; -HINSTANCE g_hInstance = 0; -HWND g_hDlgDepthChange = NULL; -HWND g_hDlgExit = NULL; -HWND g_hDlgAbout = NULL; -const char * g_pszQueryHost = NULL; -Bool g_fXdmcpEnabled = FALSE; -Bool g_fAuthEnabled = FALSE; -HICON g_hIconX = NULL; -HICON g_hSmallIconX = NULL; -#ifndef RELOCATE_PROJECTROOT -char * g_pszLogFile = DEFAULT_LOGDIR "/XWin.%s.log"; -#else -char * g_pszLogFile = "XWin.log"; -Bool g_fLogFileChanged = FALSE; -#endif -int g_iLogVerbose = 2; -Bool g_fLogInited = FALSE; -char * g_pszCommandLine = NULL; -Bool g_fSilentFatalError = FALSE; -DWORD g_dwCurrentThreadID = 0; -Bool g_fKeyboardHookLL = FALSE; -HHOOK g_hhookKeyboardLL = NULL; -HWND g_hwndKeyboardFocus = NULL; -Bool g_fNoHelpMessageBox = FALSE; -Bool g_fSoftwareCursor = FALSE; -Bool g_fSilentDupError = FALSE; - - -/* - * Global variables for dynamically loaded libraries and - * their function pointers - */ - -HMODULE g_hmodDirectDraw = NULL; -FARPROC g_fpDirectDrawCreate = NULL; -FARPROC g_fpDirectDrawCreateClipper = NULL; - -HMODULE g_hmodCommonControls = NULL; -FARPROC g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA; - - -#ifdef XWIN_CLIPBOARD -/* - * Wrapped DIX functions - */ -winDispatchProcPtr winProcEstablishConnectionOrig = NULL; -winDispatchProcPtr winProcQueryTreeOrig = NULL; -winDispatchProcPtr winProcSetSelectionOwnerOrig = NULL; - - -/* - * Clipboard variables - */ - -Bool g_fUnicodeClipboard = TRUE; -Bool g_fClipboard = FALSE; -Bool g_fClipboardLaunched = FALSE; -Bool g_fClipboardStarted = FALSE; -pthread_t g_ptClipboardProc; -HWND g_hwndClipboard = NULL; -void *g_pClipboardDisplay = NULL; -Window g_iClipboardWindow = None; -Atom g_atomLastOwnedSelection = None; -#endif - - -/* - * Re-initialize global variables that are invalidated - * by a server reset. - */ - -void -winInitializeGlobals (void) -{ - g_dwCurrentThreadID = GetCurrentThreadId (); - g_hwndKeyboardFocus = NULL; -#ifdef XWIN_CLIPBOARD - g_fClipboardLaunched = FALSE; - g_fClipboardStarted = FALSE; - g_iClipboardWindow = None; - g_pClipboardDisplay = NULL; - g_atomLastOwnedSelection = None; - g_hwndClipboard = NULL; -#endif -} +/*
+ *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
+ *Copyright (C) Colin Harrison 2005-2008
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of Harold L Hunt II
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from Harold L Hunt II.
+ *
+ * Authors: Harold L Hunt II
+ * Colin Harrison
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+
+
+/*
+ * General global variables
+ */
+
+int g_iNumScreens = 0;
+winScreenInfo g_ScreenInfo[MAXSCREENS];
+int g_iLastScreen = -1;
+#ifdef HAS_DEVWINDOWS
+int g_fdMessageQueue = WIN_FD_INVALID;
+#endif
+static int g_iScreenPrivateKeyIndex;
+DevPrivateKey g_iScreenPrivateKey = &g_iScreenPrivateKeyIndex;
+static int g_iCmapPrivateKeyIndex;
+DevPrivateKey g_iCmapPrivateKey = &g_iCmapPrivateKeyIndex;
+static int g_iGCPrivateKeyIndex;
+DevPrivateKey g_iGCPrivateKey = &g_iGCPrivateKeyIndex;
+static int g_iPixmapPrivateKeyIndex;
+DevPrivateKey g_iPixmapPrivateKey = &g_iPixmapPrivateKeyIndex;
+static int g_iWindowPrivateKeyIndex;
+DevPrivateKey g_iWindowPrivateKey = &g_iWindowPrivateKeyIndex;
+unsigned long g_ulServerGeneration = 0;
+Bool g_fInitializedDefaultScreens = FALSE;
+DWORD g_dwEnginesSupported = 0;
+HINSTANCE g_hInstance = 0;
+HWND g_hDlgDepthChange = NULL;
+HWND g_hDlgExit = NULL;
+HWND g_hDlgAbout = NULL;
+const char * g_pszQueryHost = NULL;
+Bool g_fXdmcpEnabled = FALSE;
+Bool g_fAuthEnabled = FALSE;
+HICON g_hIconX = NULL;
+HICON g_hSmallIconX = NULL;
+#ifndef RELOCATE_PROJECTROOT
+char * g_pszLogFile = DEFAULT_LOGDIR "/XWin.%s.log";
+#else
+char * g_pszLogFile = "XWin.log";
+Bool g_fLogFileChanged = FALSE;
+#endif
+int g_iLogVerbose = 2;
+Bool g_fLogInited = FALSE;
+char * g_pszCommandLine = NULL;
+Bool g_fSilentFatalError = FALSE;
+DWORD g_dwCurrentThreadID = 0;
+Bool g_fKeyboardHookLL = FALSE;
+HHOOK g_hhookKeyboardLL = NULL;
+HWND g_hwndKeyboardFocus = NULL;
+Bool g_fNoHelpMessageBox = FALSE;
+Bool g_fSoftwareCursor = FALSE;
+Bool g_fSilentDupError = FALSE;
+
+
+/*
+ * Global variables for dynamically loaded libraries and
+ * their function pointers
+ */
+
+HMODULE g_hmodDirectDraw = NULL;
+FARPROC g_fpDirectDrawCreate = NULL;
+FARPROC g_fpDirectDrawCreateClipper = NULL;
+
+HMODULE g_hmodCommonControls = NULL;
+FARPROC g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA;
+
+
+#ifdef XWIN_CLIPBOARD
+/*
+ * Wrapped DIX functions
+ */
+winDispatchProcPtr winProcEstablishConnectionOrig = NULL;
+winDispatchProcPtr winProcQueryTreeOrig = NULL;
+winDispatchProcPtr winProcSetSelectionOwnerOrig = NULL;
+
+
+/*
+ * Clipboard variables
+ */
+
+Bool g_fUnicodeClipboard = TRUE;
+Bool g_fClipboard = TRUE;
+Bool g_fClipboardLaunched = FALSE;
+Bool g_fClipboardStarted = FALSE;
+pthread_t g_ptClipboardProc;
+HWND g_hwndClipboard = NULL;
+void *g_pClipboardDisplay = NULL;
+Window g_iClipboardWindow = None;
+Atom g_atomLastOwnedSelection = None;
+#endif
+
+
+/*
+ * Re-initialize global variables that are invalidated
+ * by a server reset.
+ */
+
+void
+winInitializeGlobals (void)
+{
+ g_dwCurrentThreadID = GetCurrentThreadId ();
+ g_hwndKeyboardFocus = NULL;
+#ifdef XWIN_CLIPBOARD
+ g_fClipboardLaunched = FALSE;
+ g_fClipboardStarted = FALSE;
+ g_iClipboardWindow = None;
+ g_pClipboardDisplay = NULL;
+ g_atomLastOwnedSelection = None;
+ g_hwndClipboard = NULL;
+#endif
+}
diff --git a/xorg-server/hw/xwin/winkeybd.c b/xorg-server/hw/xwin/winkeybd.c index aa5b9a53a..bb180dff2 100644 --- a/xorg-server/hw/xwin/winkeybd.c +++ b/xorg-server/hw/xwin/winkeybd.c @@ -1,605 +1,612 @@ -/* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of the XFree86 Project - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from the XFree86 Project. - * - * Authors: Dakshinamurthy Karra - * Suhaib M Siddiqi - * Peter Busch - * Harold L Hunt II - */ - - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" -#include "winkeybd.h" -#include "winconfig.h" -#include "winmsg.h" - -#include "xkbsrv.h" - -static Bool g_winKeyState[NUM_KEYCODES]; - -/* - * Local prototypes - */ - -static void -winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap); - -static void -winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt, - pointer pCtrl, int iClass); - -static void -winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl); - - -/* - * Translate a Windows WM_[SYS]KEY(UP/DOWN) message - * into an ASCII scan code. - * - * We do this ourselves, rather than letting Windows handle it, - * because Windows tends to munge the handling of special keys, - * like AltGr on European keyboards. - */ - -void -winTranslateKey (WPARAM wParam, LPARAM lParam, int *piScanCode) -{ - int iKeyFixup = g_iKeyMap[wParam * WIN_KEYMAP_COLS + 1]; - int iKeyFixupEx = g_iKeyMap[wParam * WIN_KEYMAP_COLS + 2]; - int iParamScanCode = LOBYTE (HIWORD (lParam)); - -/* WM_ key messages faked by Vista speech recognition (WSR) don't have a - * scan code. - * - * Vocola 3 (Rick Mohr's supplement to WSR) uses - * System.Windows.Forms.SendKeys.SendWait(), which appears always to give a - * scan code of 1 - */ - if (iParamScanCode <= 1) - { - iParamScanCode = MapVirtualKeyEx(wParam, - /*MAPVK_VK_TO_VSC*/0, - GetKeyboardLayout(0)); - } - - /* Branch on special extended, special non-extended, or normal key */ - if ((HIWORD (lParam) & KF_EXTENDED) && iKeyFixupEx) - *piScanCode = iKeyFixupEx; - else if (iKeyFixup) - *piScanCode = iKeyFixup; - else if (wParam == 0 && iParamScanCode == 0x70) - *piScanCode = KEY_HKTG; - else - switch (iParamScanCode) - { - case 0x70: - *piScanCode = KEY_HKTG; - break; - case 0x73: - *piScanCode = KEY_BSlash2; - break; - default: - *piScanCode = iParamScanCode; - break; - } -} - - -/* - * We call this function from winKeybdProc when we are - * initializing the keyboard. - */ - -static void -winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap) -{ - int i; - KeySym *pMap = map; - KeySym *pKeySym; - - /* - * Initialize all key states to up... which may not be true - * but it is close enough. - */ - ZeroMemory (g_winKeyState, sizeof (g_winKeyState[0]) * NUM_KEYCODES); - - /* MAP_LENGTH is defined in Xserver/include/input.h to be 256 */ - for (i = 0; i < MAP_LENGTH; i++) - pModMap[i] = NoSymbol; /* make sure it is restored */ - - /* Loop through all valid entries in the key symbol table */ - for (pKeySym = pMap, i = MIN_KEYCODE; - i < (MIN_KEYCODE + NUM_KEYCODES); - i++, pKeySym += GLYPHS_PER_KEY) - { - switch (*pKeySym) - { - case XK_Shift_L: - case XK_Shift_R: - pModMap[i] = ShiftMask; - break; - - case XK_Control_L: - case XK_Control_R: - pModMap[i] = ControlMask; - break; - - case XK_Caps_Lock: - pModMap[i] = LockMask; - break; - - case XK_Alt_L: - case XK_Alt_R: - pModMap[i] = AltMask; - break; - - case XK_Num_Lock: - pModMap[i] = NumLockMask; - break; - - case XK_Scroll_Lock: - pModMap[i] = ScrollLockMask; - break; - -#if 0 - case XK_Super_L: - case XK_Super_R: - pModMap[i] = Mod4Mask; - break; -#else - /* Hirigana/Katakana toggle */ - case XK_Kana_Lock: - case XK_Kana_Shift: - pModMap[i] = KanaMask; - break; -#endif - - /* alternate toggle for multinational support */ - case XK_Mode_switch: - pModMap[i] = AltLangMask; - break; - } - } - - pKeySyms->map = (KeySym *) pMap; - pKeySyms->mapWidth = GLYPHS_PER_KEY; - pKeySyms->minKeyCode = MIN_KEYCODE; - pKeySyms->maxKeyCode = MAX_KEYCODE; -} - - -/* Ring the keyboard bell (system speaker on PCs) */ -static void -winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt, - pointer pCtrl, int iClass) -{ - /* - * We can't use Beep () here because it uses the PC speaker - * on NT/2000. MessageBeep (MB_OK) will play the default system - * sound on systems with a sound card or it will beep the PC speaker - * on systems that do not have a sound card. - */ - MessageBeep (MB_OK); -} - - -/* Change some keyboard configuration parameters */ -static void -winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl) -{ -} - - -/* - * See Porting Layer Definition - p. 18 - * winKeybdProc is known as a DeviceProc. - */ - -int -winKeybdProc (DeviceIntPtr pDeviceInt, int iState) -{ - DevicePtr pDevice = (DevicePtr) pDeviceInt; - XkbSrvInfoPtr xkbi; - XkbControlsPtr ctrl; - - switch (iState) - { - case DEVICE_INIT: - winConfigKeyboard (pDeviceInt); - - /* FIXME: Maybe we should use winGetKbdLeds () here? */ - defaultKeyboardControl.leds = g_winInfo.keyboard.leds; - - winDebug("Rules = \"%s\" Model = \"%s\" Layout = \"%s\"" - " Variant = \"%s\" Options = \"%s\"\n", - g_winInfo.xkb.rules ? g_winInfo.xkb.rules : "none", - g_winInfo.xkb.model ? g_winInfo.xkb.model : "none", - g_winInfo.xkb.layout ? g_winInfo.xkb.layout : "none", - g_winInfo.xkb.variant ? g_winInfo.xkb.variant : "none", - g_winInfo.xkb.options ? g_winInfo.xkb.options : "none"); - - InitKeyboardDeviceStruct (pDeviceInt, - &g_winInfo.xkb, - winKeybdBell, - winKeybdCtrl); - - xkbi = pDeviceInt->key->xkbInfo; - if ((xkbi != NULL) && (xkbi->desc != NULL)) - { - ctrl = xkbi->desc->ctrls; - ctrl->repeat_delay = g_winInfo.keyboard.delay; - ctrl->repeat_interval = 1000/g_winInfo.keyboard.rate; - } - else - { - winDebug ("winKeybdProc - Error initializing keyboard AutoRepeat\n"); - } - - XkbSetExtension(pDeviceInt, ProcessKeyboardEvent); - break; - - case DEVICE_ON: - pDevice->on = TRUE; - break; - - case DEVICE_CLOSE: - case DEVICE_OFF: - pDevice->on = FALSE; - break; - } - - return Success; -} - - -/* - * Detect current mode key states upon server startup. - * - * Simulate a press and release of any key that is currently - * toggled. - */ - -void -winInitializeModeKeyStates (void) -{ - /* Restore NumLock */ - if (GetKeyState (VK_NUMLOCK) & 0x0001) - { - winSendKeyEvent (KEY_NumLock, TRUE); - winSendKeyEvent (KEY_NumLock, FALSE); - } - - /* Restore CapsLock */ - if (GetKeyState (VK_CAPITAL) & 0x0001) - { - winSendKeyEvent (KEY_CapsLock, TRUE); - winSendKeyEvent (KEY_CapsLock, FALSE); - } - - /* Restore ScrollLock */ - if (GetKeyState (VK_SCROLL) & 0x0001) - { - winSendKeyEvent (KEY_ScrollLock, TRUE); - winSendKeyEvent (KEY_ScrollLock, FALSE); - } - - /* Restore KanaLock */ - if (GetKeyState (VK_KANA) & 0x0001) - { - winSendKeyEvent (KEY_HKTG, TRUE); - winSendKeyEvent (KEY_HKTG, FALSE); - } -} - - -/* - * Upon regaining the keyboard focus we must - * resynchronize our internal mode key states - * with the actual state of the keys. - */ - -void -winRestoreModeKeyStates (void) -{ - DWORD dwKeyState; - BOOL processEvents = TRUE; - unsigned short internalKeyStates; - - /* X server is being initialized */ - if (!inputInfo.keyboard) - return; - - /* Only process events if the rootwindow is mapped. The keyboard events - * will cause segfaults otherwise */ - if (WindowTable && WindowTable[0] && WindowTable[0]->mapped == FALSE) - processEvents = FALSE; - - /* Force to process all pending events in the mi event queue */ - if (processEvents) - mieqProcessInputEvents (); - - /* Read the mode key states of our X server */ - /* (stored in the virtual core keyboard) */ - internalKeyStates = XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state); - winDebug("winRestoreModeKeyStates: state %d\n", internalKeyStates); - - /* - * NOTE: The C XOR operator, ^, will not work here because it is - * a bitwise operator, not a logical operator. C does not - * have a logical XOR operator, so we use a macro instead. - */ - - /* Has the key state changed? */ - dwKeyState = GetKeyState (VK_NUMLOCK) & 0x0001; - if (WIN_XOR (internalKeyStates & NumLockMask, dwKeyState)) - { - winSendKeyEvent (KEY_NumLock, TRUE); - winSendKeyEvent (KEY_NumLock, FALSE); - } - - /* Has the key state changed? */ - dwKeyState = GetKeyState (VK_CAPITAL) & 0x0001; - if (WIN_XOR (internalKeyStates & LockMask, dwKeyState)) - { - winSendKeyEvent (KEY_CapsLock, TRUE); - winSendKeyEvent (KEY_CapsLock, FALSE); - } - - /* Has the key state changed? */ - dwKeyState = GetKeyState (VK_SCROLL) & 0x0001; - if (WIN_XOR (internalKeyStates & ScrollLockMask, dwKeyState)) - { - winSendKeyEvent (KEY_ScrollLock, TRUE); - winSendKeyEvent (KEY_ScrollLock, FALSE); - } - - /* Has the key state changed? */ - dwKeyState = GetKeyState (VK_KANA) & 0x0001; - if (WIN_XOR (internalKeyStates & KanaMask, dwKeyState)) - { - winSendKeyEvent (KEY_HKTG, TRUE); - winSendKeyEvent (KEY_HKTG, FALSE); - } -} - - -/* - * Look for the lovely fake Control_L press/release generated by Windows - * when AltGr is pressed/released on a non-U.S. keyboard. - */ - -Bool -winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam) -{ - MSG msgNext; - LONG lTime; - Bool fReturn; - - /* - * Fake Ctrl_L presses will be followed by an Alt_R keypress - * with the same timestamp as the Ctrl_L press. - */ - if ((message == WM_KEYDOWN || message == WM_SYSKEYDOWN) - && wParam == VK_CONTROL - && (HIWORD (lParam) & KF_EXTENDED) == 0) - { - /* Got a Ctrl_L press */ - - /* Get time of current message */ - lTime = GetMessageTime (); - - /* Look for fake Ctrl_L preceeding an Alt_R press. */ - fReturn = PeekMessage (&msgNext, NULL, - WM_KEYDOWN, WM_SYSKEYDOWN, - PM_NOREMOVE); - - /* - * Try again if the first call fails. - * NOTE: This usually happens when TweakUI is enabled. - */ - if (!fReturn) - { - /* Voodoo to make sure that the Alt_R message has posted */ - Sleep (0); - - /* Look for fake Ctrl_L preceeding an Alt_R press. */ - fReturn = PeekMessage (&msgNext, NULL, - WM_KEYDOWN, WM_SYSKEYDOWN, - PM_NOREMOVE); - } - if (msgNext.message != WM_KEYDOWN && msgNext.message != WM_SYSKEYDOWN) - fReturn = 0; - - /* Is next press an Alt_R with the same timestamp? */ - if (fReturn && msgNext.wParam == VK_MENU - && msgNext.time == lTime - && (HIWORD (msgNext.lParam) & KF_EXTENDED)) - { - /* - * Next key press is Alt_R with same timestamp as current - * Ctrl_L message. Therefore, this Ctrl_L press is a fake - * event, so discard it. - */ - return TRUE; - } - } - - /* - * Fake Ctrl_L releases will be followed by an Alt_R release - * with the same timestamp as the Ctrl_L release. - */ - if ((message == WM_KEYUP || message == WM_SYSKEYUP) - && wParam == VK_CONTROL - && (HIWORD (lParam) & KF_EXTENDED) == 0) - { - /* Got a Ctrl_L release */ - - /* Get time of current message */ - lTime = GetMessageTime (); - - /* Look for fake Ctrl_L release preceeding an Alt_R release. */ - fReturn = PeekMessage (&msgNext, NULL, - WM_KEYUP, WM_SYSKEYUP, - PM_NOREMOVE); - - /* - * Try again if the first call fails. - * NOTE: This usually happens when TweakUI is enabled. - */ - if (!fReturn) - { - /* Voodoo to make sure that the Alt_R message has posted */ - Sleep (0); - - /* Look for fake Ctrl_L release preceeding an Alt_R release. */ - fReturn = PeekMessage (&msgNext, NULL, - WM_KEYUP, WM_SYSKEYUP, - PM_NOREMOVE); - } - - if (msgNext.message != WM_KEYUP && msgNext.message != WM_SYSKEYUP) - fReturn = 0; - - /* Is next press an Alt_R with the same timestamp? */ - if (fReturn - && (msgNext.message == WM_KEYUP - || msgNext.message == WM_SYSKEYUP) - && msgNext.wParam == VK_MENU - && msgNext.time == lTime - && (HIWORD (msgNext.lParam) & KF_EXTENDED)) - { - /* - * Next key release is Alt_R with same timestamp as current - * Ctrl_L message. Therefore, this Ctrl_L release is a fake - * event, so discard it. - */ - return TRUE; - } - } - - /* Not a fake control left press/release */ - return FALSE; -} - - -/* - * Lift any modifier keys that are pressed - */ - -void -winKeybdReleaseKeys (void) -{ - int i; - -#ifdef HAS_DEVWINDOWS - /* Verify that the mi input system has been initialized */ - if (g_fdMessageQueue == WIN_FD_INVALID) - return; -#endif - - /* Loop through all keys */ - for (i = 0; i < NUM_KEYCODES; ++i) - { - /* Pop key if pressed */ - if (g_winKeyState[i]) - winSendKeyEvent (i, FALSE); - - /* Reset pressed flag for keys */ - g_winKeyState[i] = FALSE; - } -} - - -/* - * Take a raw X key code and send an up or down event for it. - * - * Thanks to VNC for inspiration, though it is a simple function. - */ - -void -winSendKeyEvent (DWORD dwKey, Bool fDown) -{ - EventListPtr events; - int i, nevents; - - /* - * When alt-tabing between screens we can get phantom key up messages - * Here we only pass them through it we think we should! - */ - if (g_winKeyState[dwKey] == FALSE && fDown == FALSE) return; - - /* Update the keyState map */ - g_winKeyState[dwKey] = fDown; - - GetEventList(&events); - nevents = GetKeyboardEvents(events, g_pwinKeyboard, fDown ? KeyPress : KeyRelease, dwKey + MIN_KEYCODE); - - for (i = 0; i < nevents; i++) - mieqEnqueue(g_pwinKeyboard, (InternalEvent*)(events + i)->event); - - winDebug("winSendKeyEvent: dwKey: %d, fDown: %d, nEvents %d\n", - dwKey, fDown, nevents); -} - -BOOL winCheckKeyPressed(WPARAM wParam, LPARAM lParam) -{ - switch (wParam) - { - case VK_CONTROL: - if ((lParam & 0x1ff0000) == 0x11d0000 && g_winKeyState[KEY_RCtrl]) - return TRUE; - if ((lParam & 0x1ff0000) == 0x01d0000 && g_winKeyState[KEY_LCtrl]) - return TRUE; - break; - case VK_SHIFT: - if ((lParam & 0x1ff0000) == 0x0360000 && g_winKeyState[KEY_ShiftR]) - return TRUE; - if ((lParam & 0x1ff0000) == 0x02a0000 && g_winKeyState[KEY_ShiftL]) - return TRUE; - break; - default: - return TRUE; - } - return FALSE; -} - -/* Only on shift release message is sent even if both are pressed. - * Fix this here - */ -void winFixShiftKeys (int iScanCode) -{ - if (GetKeyState (VK_SHIFT) & 0x8000) - return; - - if (iScanCode == KEY_ShiftL && g_winKeyState[KEY_ShiftR]) - winSendKeyEvent (KEY_ShiftR, FALSE); - if (iScanCode == KEY_ShiftR && g_winKeyState[KEY_ShiftL]) - winSendKeyEvent (KEY_ShiftL, FALSE); -} +/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Dakshinamurthy Karra
+ * Suhaib M Siddiqi
+ * Peter Busch
+ * Harold L Hunt II
+ */
+
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#include "winkeybd.h"
+#include "winconfig.h"
+#include "winmsg.h"
+
+#include "xkbsrv.h"
+
+static Bool g_winKeyState[NUM_KEYCODES];
+
+/*
+ * Local prototypes
+ */
+
+static void
+winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap);
+
+static void
+winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt,
+ pointer pCtrl, int iClass);
+
+static void
+winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl);
+
+
+/*
+ * Translate a Windows WM_[SYS]KEY(UP/DOWN) message
+ * into an ASCII scan code.
+ *
+ * We do this ourselves, rather than letting Windows handle it,
+ * because Windows tends to munge the handling of special keys,
+ * like AltGr on European keyboards.
+ */
+
+void
+winTranslateKey (WPARAM wParam, LPARAM lParam, int *piScanCode)
+{
+ int iKeyFixup = g_iKeyMap[wParam * WIN_KEYMAP_COLS + 1];
+ int iKeyFixupEx = g_iKeyMap[wParam * WIN_KEYMAP_COLS + 2];
+ int iParam = HIWORD (lParam);
+ int iParamScanCode = LOBYTE (iParam);
+
+/* WM_ key messages faked by Vista speech recognition (WSR) don't have a
+ * scan code.
+ *
+ * Vocola 3 (Rick Mohr's supplement to WSR) uses
+ * System.Windows.Forms.SendKeys.SendWait(), which appears always to give a
+ * scan code of 1
+ */
+ if (iParamScanCode <= 1)
+ {
+ if (VK_PRIOR <= wParam && wParam <= VK_DOWN)
+ /* Trigger special case table to translate to extended
+ * keycode, otherwise if num_lock is on, we can get keypad
+ * numbers instead of navigation keys. */
+ iParam |= KF_EXTENDED;
+ else
+ iParamScanCode = MapVirtualKeyEx(wParam,
+ /*MAPVK_VK_TO_VSC*/0,
+ GetKeyboardLayout(0));
+ }
+
+ /* Branch on special extended, special non-extended, or normal key */
+ if ((iParam & KF_EXTENDED) && iKeyFixupEx)
+ *piScanCode = iKeyFixupEx;
+ else if (iKeyFixup)
+ *piScanCode = iKeyFixup;
+ else if (wParam == 0 && iParamScanCode == 0x70)
+ *piScanCode = KEY_HKTG;
+ else
+ switch (iParamScanCode)
+ {
+ case 0x70:
+ *piScanCode = KEY_HKTG;
+ break;
+ case 0x73:
+ *piScanCode = KEY_BSlash2;
+ break;
+ default:
+ *piScanCode = iParamScanCode;
+ break;
+ }
+}
+
+
+/*
+ * We call this function from winKeybdProc when we are
+ * initializing the keyboard.
+ */
+
+static void
+winGetKeyMappings (KeySymsPtr pKeySyms, CARD8 *pModMap)
+{
+ int i;
+ KeySym *pMap = map;
+ KeySym *pKeySym;
+
+ /*
+ * Initialize all key states to up... which may not be true
+ * but it is close enough.
+ */
+ ZeroMemory (g_winKeyState, sizeof (g_winKeyState[0]) * NUM_KEYCODES);
+
+ /* MAP_LENGTH is defined in Xserver/include/input.h to be 256 */
+ for (i = 0; i < MAP_LENGTH; i++)
+ pModMap[i] = NoSymbol; /* make sure it is restored */
+
+ /* Loop through all valid entries in the key symbol table */
+ for (pKeySym = pMap, i = MIN_KEYCODE;
+ i < (MIN_KEYCODE + NUM_KEYCODES);
+ i++, pKeySym += GLYPHS_PER_KEY)
+ {
+ switch (*pKeySym)
+ {
+ case XK_Shift_L:
+ case XK_Shift_R:
+ pModMap[i] = ShiftMask;
+ break;
+
+ case XK_Control_L:
+ case XK_Control_R:
+ pModMap[i] = ControlMask;
+ break;
+
+ case XK_Caps_Lock:
+ pModMap[i] = LockMask;
+ break;
+
+ case XK_Alt_L:
+ case XK_Alt_R:
+ pModMap[i] = AltMask;
+ break;
+
+ case XK_Num_Lock:
+ pModMap[i] = NumLockMask;
+ break;
+
+ case XK_Scroll_Lock:
+ pModMap[i] = ScrollLockMask;
+ break;
+
+#if 0
+ case XK_Super_L:
+ case XK_Super_R:
+ pModMap[i] = Mod4Mask;
+ break;
+#else
+ /* Hirigana/Katakana toggle */
+ case XK_Kana_Lock:
+ case XK_Kana_Shift:
+ pModMap[i] = KanaMask;
+ break;
+#endif
+
+ /* alternate toggle for multinational support */
+ case XK_Mode_switch:
+ pModMap[i] = AltLangMask;
+ break;
+ }
+ }
+
+ pKeySyms->map = (KeySym *) pMap;
+ pKeySyms->mapWidth = GLYPHS_PER_KEY;
+ pKeySyms->minKeyCode = MIN_KEYCODE;
+ pKeySyms->maxKeyCode = MAX_KEYCODE;
+}
+
+
+/* Ring the keyboard bell (system speaker on PCs) */
+static void
+winKeybdBell (int iPercent, DeviceIntPtr pDeviceInt,
+ pointer pCtrl, int iClass)
+{
+ /*
+ * We can't use Beep () here because it uses the PC speaker
+ * on NT/2000. MessageBeep (MB_OK) will play the default system
+ * sound on systems with a sound card or it will beep the PC speaker
+ * on systems that do not have a sound card.
+ */
+ MessageBeep (MB_OK);
+}
+
+
+/* Change some keyboard configuration parameters */
+static void
+winKeybdCtrl (DeviceIntPtr pDevice, KeybdCtrl *pCtrl)
+{
+}
+
+
+/*
+ * See Porting Layer Definition - p. 18
+ * winKeybdProc is known as a DeviceProc.
+ */
+
+int
+winKeybdProc (DeviceIntPtr pDeviceInt, int iState)
+{
+ DevicePtr pDevice = (DevicePtr) pDeviceInt;
+ XkbSrvInfoPtr xkbi;
+ XkbControlsPtr ctrl;
+
+ switch (iState)
+ {
+ case DEVICE_INIT:
+ winConfigKeyboard (pDeviceInt);
+
+ /* FIXME: Maybe we should use winGetKbdLeds () here? */
+ defaultKeyboardControl.leds = g_winInfo.keyboard.leds;
+
+ winDebug("Rules = \"%s\" Model = \"%s\" Layout = \"%s\""
+ " Variant = \"%s\" Options = \"%s\"\n",
+ g_winInfo.xkb.rules ? g_winInfo.xkb.rules : "none",
+ g_winInfo.xkb.model ? g_winInfo.xkb.model : "none",
+ g_winInfo.xkb.layout ? g_winInfo.xkb.layout : "none",
+ g_winInfo.xkb.variant ? g_winInfo.xkb.variant : "none",
+ g_winInfo.xkb.options ? g_winInfo.xkb.options : "none");
+
+ InitKeyboardDeviceStruct (pDeviceInt,
+ &g_winInfo.xkb,
+ winKeybdBell,
+ winKeybdCtrl);
+
+ xkbi = pDeviceInt->key->xkbInfo;
+ if ((xkbi != NULL) && (xkbi->desc != NULL))
+ {
+ ctrl = xkbi->desc->ctrls;
+ ctrl->repeat_delay = g_winInfo.keyboard.delay;
+ ctrl->repeat_interval = 1000/g_winInfo.keyboard.rate;
+ }
+ else
+ {
+ winDebug ("winKeybdProc - Error initializing keyboard AutoRepeat\n");
+ }
+
+ XkbSetExtension(pDeviceInt, ProcessKeyboardEvent);
+ break;
+
+ case DEVICE_ON:
+ pDevice->on = TRUE;
+ break;
+
+ case DEVICE_CLOSE:
+ case DEVICE_OFF:
+ pDevice->on = FALSE;
+ break;
+ }
+
+ return Success;
+}
+
+
+/*
+ * Detect current mode key states upon server startup.
+ *
+ * Simulate a press and release of any key that is currently
+ * toggled.
+ */
+
+void
+winInitializeModeKeyStates (void)
+{
+ /* Restore NumLock */
+ if (GetKeyState (VK_NUMLOCK) & 0x0001)
+ {
+ winSendKeyEvent (KEY_NumLock, TRUE);
+ winSendKeyEvent (KEY_NumLock, FALSE);
+ }
+
+ /* Restore CapsLock */
+ if (GetKeyState (VK_CAPITAL) & 0x0001)
+ {
+ winSendKeyEvent (KEY_CapsLock, TRUE);
+ winSendKeyEvent (KEY_CapsLock, FALSE);
+ }
+
+ /* Restore ScrollLock */
+ if (GetKeyState (VK_SCROLL) & 0x0001)
+ {
+ winSendKeyEvent (KEY_ScrollLock, TRUE);
+ winSendKeyEvent (KEY_ScrollLock, FALSE);
+ }
+
+ /* Restore KanaLock */
+ if (GetKeyState (VK_KANA) & 0x0001)
+ {
+ winSendKeyEvent (KEY_HKTG, TRUE);
+ winSendKeyEvent (KEY_HKTG, FALSE);
+ }
+}
+
+
+/*
+ * Upon regaining the keyboard focus we must
+ * resynchronize our internal mode key states
+ * with the actual state of the keys.
+ */
+
+void
+winRestoreModeKeyStates (void)
+{
+ DWORD dwKeyState;
+ BOOL processEvents = TRUE;
+ unsigned short internalKeyStates;
+
+ /* X server is being initialized */
+ if (!inputInfo.keyboard)
+ return;
+
+ /* Only process events if the rootwindow is mapped. The keyboard events
+ * will cause segfaults otherwise */
+ if (WindowTable && WindowTable[0] && WindowTable[0]->mapped == FALSE)
+ processEvents = FALSE;
+
+ /* Force to process all pending events in the mi event queue */
+ if (processEvents)
+ mieqProcessInputEvents ();
+
+ /* Read the mode key states of our X server */
+ /* (stored in the virtual core keyboard) */
+ internalKeyStates = XkbStateFieldFromRec(&inputInfo.keyboard->key->xkbInfo->state);
+ winDebug("winRestoreModeKeyStates: state %d\n", internalKeyStates);
+
+ /*
+ * NOTE: The C XOR operator, ^, will not work here because it is
+ * a bitwise operator, not a logical operator. C does not
+ * have a logical XOR operator, so we use a macro instead.
+ */
+
+ /* Has the key state changed? */
+ dwKeyState = GetKeyState (VK_NUMLOCK) & 0x0001;
+ if (WIN_XOR (internalKeyStates & NumLockMask, dwKeyState))
+ {
+ winSendKeyEvent (KEY_NumLock, TRUE);
+ winSendKeyEvent (KEY_NumLock, FALSE);
+ }
+
+ /* Has the key state changed? */
+ dwKeyState = GetKeyState (VK_CAPITAL) & 0x0001;
+ if (WIN_XOR (internalKeyStates & LockMask, dwKeyState))
+ {
+ winSendKeyEvent (KEY_CapsLock, TRUE);
+ winSendKeyEvent (KEY_CapsLock, FALSE);
+ }
+
+ /* Has the key state changed? */
+ dwKeyState = GetKeyState (VK_SCROLL) & 0x0001;
+ if (WIN_XOR (internalKeyStates & ScrollLockMask, dwKeyState))
+ {
+ winSendKeyEvent (KEY_ScrollLock, TRUE);
+ winSendKeyEvent (KEY_ScrollLock, FALSE);
+ }
+
+ /* Has the key state changed? */
+ dwKeyState = GetKeyState (VK_KANA) & 0x0001;
+ if (WIN_XOR (internalKeyStates & KanaMask, dwKeyState))
+ {
+ winSendKeyEvent (KEY_HKTG, TRUE);
+ winSendKeyEvent (KEY_HKTG, FALSE);
+ }
+}
+
+
+/*
+ * Look for the lovely fake Control_L press/release generated by Windows
+ * when AltGr is pressed/released on a non-U.S. keyboard.
+ */
+
+Bool
+winIsFakeCtrl_L (UINT message, WPARAM wParam, LPARAM lParam)
+{
+ MSG msgNext;
+ LONG lTime;
+ Bool fReturn;
+
+ /*
+ * Fake Ctrl_L presses will be followed by an Alt_R keypress
+ * with the same timestamp as the Ctrl_L press.
+ */
+ if ((message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
+ && wParam == VK_CONTROL
+ && (HIWORD (lParam) & KF_EXTENDED) == 0)
+ {
+ /* Got a Ctrl_L press */
+
+ /* Get time of current message */
+ lTime = GetMessageTime ();
+
+ /* Look for fake Ctrl_L preceeding an Alt_R press. */
+ fReturn = PeekMessage (&msgNext, NULL,
+ WM_KEYDOWN, WM_SYSKEYDOWN,
+ PM_NOREMOVE);
+
+ /*
+ * Try again if the first call fails.
+ * NOTE: This usually happens when TweakUI is enabled.
+ */
+ if (!fReturn)
+ {
+ /* Voodoo to make sure that the Alt_R message has posted */
+ Sleep (0);
+
+ /* Look for fake Ctrl_L preceeding an Alt_R press. */
+ fReturn = PeekMessage (&msgNext, NULL,
+ WM_KEYDOWN, WM_SYSKEYDOWN,
+ PM_NOREMOVE);
+ }
+ if (msgNext.message != WM_KEYDOWN && msgNext.message != WM_SYSKEYDOWN)
+ fReturn = 0;
+
+ /* Is next press an Alt_R with the same timestamp? */
+ if (fReturn && msgNext.wParam == VK_MENU
+ && msgNext.time == lTime
+ && (HIWORD (msgNext.lParam) & KF_EXTENDED))
+ {
+ /*
+ * Next key press is Alt_R with same timestamp as current
+ * Ctrl_L message. Therefore, this Ctrl_L press is a fake
+ * event, so discard it.
+ */
+ return TRUE;
+ }
+ }
+
+ /*
+ * Fake Ctrl_L releases will be followed by an Alt_R release
+ * with the same timestamp as the Ctrl_L release.
+ */
+ if ((message == WM_KEYUP || message == WM_SYSKEYUP)
+ && wParam == VK_CONTROL
+ && (HIWORD (lParam) & KF_EXTENDED) == 0)
+ {
+ /* Got a Ctrl_L release */
+
+ /* Get time of current message */
+ lTime = GetMessageTime ();
+
+ /* Look for fake Ctrl_L release preceeding an Alt_R release. */
+ fReturn = PeekMessage (&msgNext, NULL,
+ WM_KEYUP, WM_SYSKEYUP,
+ PM_NOREMOVE);
+
+ /*
+ * Try again if the first call fails.
+ * NOTE: This usually happens when TweakUI is enabled.
+ */
+ if (!fReturn)
+ {
+ /* Voodoo to make sure that the Alt_R message has posted */
+ Sleep (0);
+
+ /* Look for fake Ctrl_L release preceeding an Alt_R release. */
+ fReturn = PeekMessage (&msgNext, NULL,
+ WM_KEYUP, WM_SYSKEYUP,
+ PM_NOREMOVE);
+ }
+
+ if (msgNext.message != WM_KEYUP && msgNext.message != WM_SYSKEYUP)
+ fReturn = 0;
+
+ /* Is next press an Alt_R with the same timestamp? */
+ if (fReturn
+ && (msgNext.message == WM_KEYUP
+ || msgNext.message == WM_SYSKEYUP)
+ && msgNext.wParam == VK_MENU
+ && msgNext.time == lTime
+ && (HIWORD (msgNext.lParam) & KF_EXTENDED))
+ {
+ /*
+ * Next key release is Alt_R with same timestamp as current
+ * Ctrl_L message. Therefore, this Ctrl_L release is a fake
+ * event, so discard it.
+ */
+ return TRUE;
+ }
+ }
+
+ /* Not a fake control left press/release */
+ return FALSE;
+}
+
+
+/*
+ * Lift any modifier keys that are pressed
+ */
+
+void
+winKeybdReleaseKeys (void)
+{
+ int i;
+
+#ifdef HAS_DEVWINDOWS
+ /* Verify that the mi input system has been initialized */
+ if (g_fdMessageQueue == WIN_FD_INVALID)
+ return;
+#endif
+
+ /* Loop through all keys */
+ for (i = 0; i < NUM_KEYCODES; ++i)
+ {
+ /* Pop key if pressed */
+ if (g_winKeyState[i])
+ winSendKeyEvent (i, FALSE);
+
+ /* Reset pressed flag for keys */
+ g_winKeyState[i] = FALSE;
+ }
+}
+
+
+/*
+ * Take a raw X key code and send an up or down event for it.
+ *
+ * Thanks to VNC for inspiration, though it is a simple function.
+ */
+
+void
+winSendKeyEvent (DWORD dwKey, Bool fDown)
+{
+ EventListPtr events;
+ int i, nevents;
+
+ /*
+ * When alt-tabing between screens we can get phantom key up messages
+ * Here we only pass them through it we think we should!
+ */
+ if (g_winKeyState[dwKey] == FALSE && fDown == FALSE) return;
+
+ /* Update the keyState map */
+ g_winKeyState[dwKey] = fDown;
+
+ GetEventList(&events);
+ nevents = GetKeyboardEvents(events, g_pwinKeyboard, fDown ? KeyPress : KeyRelease, dwKey + MIN_KEYCODE);
+
+ for (i = 0; i < nevents; i++)
+ mieqEnqueue(g_pwinKeyboard, (InternalEvent*)(events + i)->event);
+
+ winDebug("winSendKeyEvent: dwKey: %d, fDown: %d, nEvents %d\n",
+ dwKey, fDown, nevents);
+}
+
+BOOL winCheckKeyPressed(WPARAM wParam, LPARAM lParam)
+{
+ switch (wParam)
+ {
+ case VK_CONTROL:
+ if ((lParam & 0x1ff0000) == 0x11d0000 && g_winKeyState[KEY_RCtrl])
+ return TRUE;
+ if ((lParam & 0x1ff0000) == 0x01d0000 && g_winKeyState[KEY_LCtrl])
+ return TRUE;
+ break;
+ case VK_SHIFT:
+ if ((lParam & 0x1ff0000) == 0x0360000 && g_winKeyState[KEY_ShiftR])
+ return TRUE;
+ if ((lParam & 0x1ff0000) == 0x02a0000 && g_winKeyState[KEY_ShiftL])
+ return TRUE;
+ break;
+ default:
+ return TRUE;
+ }
+ return FALSE;
+}
+
+/* Only on shift release message is sent even if both are pressed.
+ * Fix this here
+ */
+void winFixShiftKeys (int iScanCode)
+{
+ if (GetKeyState (VK_SHIFT) & 0x8000)
+ return;
+
+ if (iScanCode == KEY_ShiftL && g_winKeyState[KEY_ShiftR])
+ winSendKeyEvent (KEY_ShiftR, FALSE);
+ if (iScanCode == KEY_ShiftR && g_winKeyState[KEY_ShiftL])
+ winSendKeyEvent (KEY_ShiftL, FALSE);
+}
diff --git a/xorg-server/hw/xwin/winkeybd.h b/xorg-server/hw/xwin/winkeybd.h index d5b115736..8646bcec8 100644 --- a/xorg-server/hw/xwin/winkeybd.h +++ b/xorg-server/hw/xwin/winkeybd.h @@ -1,314 +1,314 @@ -#if !defined(WINKEYBD_H) -#define WINKEYBD_H -/* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of the XFree86 Project - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from the XFree86 Project. - * - * Authors: Harold L Hunt II - */ - -/* - * We need symbols for the scan codes of keys. - */ -#include "winkeynames.h" - - -/* - * Include the standard ASCII keymap. - * - * This header declares a static KeySym array called 'map'. - */ -#include "winkeymap.h" - -#define WIN_KEYMAP_COLS 3 - -/* ASCII column, rows 33 through 40 are for Speech Recognition with - * num-lock asserted. - * Rows 160 through 165 correspond to software-generated codes, which - * may not be associated with the appropriate scan code/extended bit - */ -const int -g_iKeyMap [] = { - /* count Windows VK, ASCII, ASCII when extended VK */ - /* 0 */ 0, 0, 0, - /* 1 */ 0, 0, 0, - /* 2 */ 0, 0, 0, - /* 3 */ VK_CANCEL, 0, KEY_Break, - /* 4 */ 0, 0, 0, - /* 5 */ 0, 0, 0, - /* 6 */ 0, 0, 0, - /* 7 */ 0, 0, 0, - /* 8 */ 0, 0, 0, - /* 9 */ 0, 0, 0, - /* 10 */ 0, 0, 0, - /* 11 */ 0, 0, 0, - /* 12 */ 0, 0, 0, - /* 13 */ VK_RETURN, 0, KEY_KP_Enter, - /* 14 */ 0, 0, 0, - /* 15 */ 0, 0, 0, - /* 16 */ VK_SHIFT, 0, 0, - /* 17 */ VK_CONTROL, 0, KEY_RCtrl, - /* 18 */ VK_MENU, 0, KEY_AltLang, - /* 19 */ VK_PAUSE, KEY_Pause, 0, - /* 20 */ 0, 0, 0, - /* 21 */ 0, 0, 0, - /* 22 */ 0, 0, 0, - /* 23 */ 0, 0, 0, - /* 24 */ 0, 0, 0, - /* 25 */ 0, 0, 0, - /* 26 */ 0, 0, 0, - /* 27 */ 0, 0, 0, - /* 28 */ 0, 0, 0, - /* 29 */ 0, 0, 0, - /* 30 */ 0, 0, 0, - /* 31 */ 0, 0, 0, - /* 32 */ 0, 0, 0, - /* 33 */ VK_PRIOR, KEY_PgUp, KEY_PgUp, - /* 34 */ VK_NEXT, KEY_PgDown, KEY_PgDown, - /* 35 */ VK_END, KEY_End, KEY_End, - /* 36 */ VK_HOME, KEY_Home, KEY_Home, - /* 37 */ VK_LEFT, KEY_Left, KEY_Left, - /* 38 */ VK_UP, KEY_Up, KEY_Up, - /* 39 */ VK_RIGHT, KEY_Right, KEY_Right, - /* 40 */ VK_DOWN, KEY_Down, KEY_Down, - /* 41 */ 0, 0, 0, - /* 42 */ 0, 0, 0, - /* 43 */ 0, 0, 0, - /* 44 */ VK_SNAPSHOT, 0, KEY_Print, - /* 45 */ VK_INSERT, 0, KEY_Insert, - /* 46 */ VK_DELETE, 0, KEY_Delete, - /* 47 */ 0, 0, 0, - /* 48 */ 0, 0, 0, - /* 49 */ 0, 0, 0, - /* 50 */ 0, 0, 0, - /* 51 */ 0, 0, 0, - /* 52 */ 0, 0, 0, - /* 53 */ 0, 0, 0, - /* 54 */ 0, 0, 0, - /* 55 */ 0, 0, 0, - /* 56 */ 0, 0, 0, - /* 57 */ 0, 0, 0, - /* 58 */ 0, 0, 0, - /* 59 */ 0, 0, 0, - /* 60 */ 0, 0, 0, - /* 61 */ 0, 0, 0, - /* 62 */ 0, 0, 0, - /* 63 */ 0, 0, 0, - /* 64 */ 0, 0, 0, - /* 65 */ 0, 0, 0, - /* 66 */ 0, 0, 0, - /* 67 */ 0, 0, 0, - /* 68 */ 0, 0, 0, - /* 69 */ 0, 0, 0, - /* 70 */ 0, 0, 0, - /* 71 */ 0, 0, 0, - /* 72 */ 0, 0, 0, - /* 73 */ 0, 0, 0, - /* 74 */ 0, 0, 0, - /* 75 */ 0, 0, 0, - /* 76 */ 0, 0, 0, - /* 77 */ 0, 0, 0, - /* 78 */ 0, 0, 0, - /* 79 */ 0, 0, 0, - /* 80 */ 0, 0, 0, - /* 81 */ 0, 0, 0, - /* 82 */ 0, 0, 0, - /* 83 */ 0, 0, 0, - /* 84 */ 0, 0, 0, - /* 85 */ 0, 0, 0, - /* 86 */ 0, 0, 0, - /* 87 */ 0, 0, 0, - /* 88 */ 0, 0, 0, - /* 89 */ 0, 0, 0, - /* 90 */ 0, 0, 0, - /* 91 */ VK_LWIN, KEY_LMeta, 0, - /* 92 */ VK_RWIN, KEY_RMeta, 0, - /* 93 */ VK_APPS, KEY_Menu, 0, - /* 94 */ 0, 0, 0, - /* 95 */ 0, 0, 0, - /* 96 */ 0, 0, 0, - /* 97 */ 0, 0, 0, - /* 98 */ 0, 0, 0, - /* 99 */ 0, 0, 0, - /* 100 */ 0, 0, 0, - /* 101 */ 0, 0, 0, - /* 102 */ 0, 0, 0, - /* 103 */ 0, 0, 0, - /* 104 */ 0, 0, 0, - /* 105 */ 0, 0, 0, - /* 106 */ 0, 0, 0, - /* 107 */ 0, 0, 0, - /* 108 */ 0, 0, 0, - /* 109 */ 0, 0, 0, - /* 110 */ 0, 0, 0, - /* 111 */ VK_DIVIDE, 0, KEY_KP_Divide, - /* 112 */ 0, 0, 0, - /* 113 */ 0, 0, 0, - /* 114 */ 0, 0, 0, - /* 115 */ 0, 0, 0, - /* 116 */ 0, 0, 0, - /* 117 */ 0, 0, 0, - /* 118 */ 0, 0, 0, - /* 119 */ 0, 0, 0, - /* 120 */ 0, 0, 0, - /* 121 */ 0, 0, 0, - /* 122 */ 0, 0, 0, - /* 123 */ 0, 0, 0, - /* 124 */ 0, 0, 0, - /* 125 */ 0, 0, 0, - /* 126 */ 0, 0, 0, - /* 127 */ 0, 0, 0, - /* 128 */ 0, 0, 0, - /* 129 */ 0, 0, 0, - /* 130 */ 0, 0, 0, - /* 131 */ 0, 0, 0, - /* 132 */ 0, 0, 0, - /* 133 */ 0, 0, 0, - /* 134 */ 0, 0, 0, - /* 135 */ 0, 0, 0, - /* 136 */ 0, 0, 0, - /* 137 */ 0, 0, 0, - /* 138 */ 0, 0, 0, - /* 139 */ 0, 0, 0, - /* 140 */ 0, 0, 0, - /* 141 */ 0, 0, 0, - /* 142 */ 0, 0, 0, - /* 143 */ 0, 0, 0, - /* 144 */ 0, 0, 0, - /* 145 */ 0, 0, 0, - /* 146 */ 0, 0, 0, - /* 147 */ 0, 0, 0, - /* 148 */ 0, 0, 0, - /* 149 */ 0, 0, 0, - /* 150 */ 0, 0, 0, - /* 151 */ 0, 0, 0, - /* 152 */ 0, 0, 0, - /* 153 */ 0, 0, 0, - /* 154 */ 0, 0, 0, - /* 155 */ 0, 0, 0, - /* 156 */ 0, 0, 0, - /* 157 */ 0, 0, 0, - /* 158 */ 0, 0, 0, - /* 159 */ 0, 0, 0, - /* 160 */ VK_LSHIFT, KEY_ShiftL, KEY_ShiftL, - /* 161 */ VK_RSHIFT, KEY_ShiftR, KEY_ShiftR, - /* 162 */ VK_LCONTROL, KEY_LCtrl, KEY_LCtrl, - /* 163 */ VK_RCONTROL, KEY_RCtrl, KEY_RCtrl, - /* 164 */ VK_LMENU, KEY_Alt, KEY_Alt, - /* 165 */ VK_RMENU, KEY_AltLang, KEY_AltLang, - /* 166 */ 0, 0, 0, - /* 167 */ 0, 0, 0, - /* 168 */ 0, 0, 0, - /* 169 */ 0, 0, 0, - /* 170 */ 0, 0, 0, - /* 171 */ 0, 0, 0, - /* 172 */ 0, 0, 0, - /* 173 */ 0, 0, 0, - /* 174 */ 0, 0, 0, - /* 175 */ 0, 0, 0, - /* 176 */ 0, 0, 0, - /* 177 */ 0, 0, 0, - /* 178 */ 0, 0, 0, - /* 179 */ 0, 0, 0, - /* 180 */ 0, 0, 0, - /* 181 */ 0, 0, 0, - /* 182 */ 0, 0, 0, - /* 183 */ 0, 0, 0, - /* 184 */ 0, 0, 0, - /* 185 */ 0, 0, 0, - /* 186 */ 0, 0, 0, - /* 187 */ 0, 0, 0, - /* 188 */ 0, 0, 0, - /* 189 */ 0, 0, 0, - /* 190 */ 0, 0, 0, - /* 191 */ 0, 0, 0, - /* 192 */ 0, 0, 0, - /* 193 */ 0, 0, 0, - /* 194 */ 0, 0, 0, - /* 195 */ 0, 0, 0, - /* 196 */ 0, 0, 0, - /* 197 */ 0, 0, 0, - /* 198 */ 0, 0, 0, - /* 199 */ 0, 0, 0, - /* 200 */ 0, 0, 0, - /* 201 */ 0, 0, 0, - /* 202 */ 0, 0, 0, - /* 203 */ 0, 0, 0, - /* 204 */ 0, 0, 0, - /* 205 */ 0, 0, 0, - /* 206 */ 0, 0, 0, - /* 207 */ 0, 0, 0, - /* 208 */ 0, 0, 0, - /* 209 */ 0, 0, 0, - /* 210 */ 0, 0, 0, - /* 211 */ 0, 0, 0, - /* 212 */ 0, 0, 0, - /* 213 */ 0, 0, 0, - /* 214 */ 0, 0, 0, - /* 215 */ 0, 0, 0, - /* 216 */ 0, 0, 0, - /* 217 */ 0, 0, 0, - /* 218 */ 0, 0, 0, - /* 219 */ 0, 0, 0, - /* 220 */ 0, 0, 0, - /* 221 */ 0, 0, 0, - /* 222 */ 0, 0, 0, - /* 223 */ 0, 0, 0, - /* 224 */ 0, 0, 0, - /* 225 */ 0, 0, 0, - /* 226 */ 0, 0, 0, - /* 227 */ 0, 0, 0, - /* 228 */ 0, 0, 0, - /* 229 */ 0, 0, 0, - /* 230 */ 0, 0, 0, - /* 231 */ 0, 0, 0, - /* 232 */ 0, 0, 0, - /* 233 */ 0, 0, 0, - /* 234 */ 0, 0, 0, - /* 235 */ 0, 0, 0, - /* 236 */ 0, 0, 0, - /* 237 */ 0, 0, 0, - /* 238 */ 0, 0, 0, - /* 239 */ 0, 0, 0, - /* 240 */ 0, 0, 0, - /* 241 */ 0, 0, 0, - /* 242 */ 0, 0, 0, - /* 243 */ 0, 0, 0, - /* 244 */ 0, 0, 0, - /* 245 */ 0, 0, 0, - /* 246 */ 0, 0, 0, - /* 247 */ 0, 0, 0, - /* 248 */ 0, 0, 0, - /* 249 */ 0, 0, 0, - /* 250 */ 0, 0, 0, - /* 251 */ 0, 0, 0, - /* 252 */ 0, 0, 0, - /* 253 */ 0, 0, 0, - /* 254 */ 0, 0, 0, - /* 255 */ 0, 0, 0 -}; - -#endif /* WINKEYBD_H */ +#if !defined(WINKEYBD_H)
+#define WINKEYBD_H
+/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Harold L Hunt II
+ */
+
+/*
+ * We need symbols for the scan codes of keys.
+ */
+#include "winkeynames.h"
+
+
+/*
+ * Include the standard ASCII keymap.
+ *
+ * This header declares a static KeySym array called 'map'.
+ */
+#include "winkeymap.h"
+
+#define WIN_KEYMAP_COLS 3
+
+/* ASCII column, rows 33 through 40 are for Speech Recognition with
+ * num-lock asserted.
+ * Rows 160 through 165 correspond to software-generated codes, which
+ * may not be associated with the appropriate scan code/extended bit
+ */
+const int
+g_iKeyMap [] = {
+ /* count Windows VK, ASCII, ASCII when extended VK */
+ /* 0 */ 0, 0, 0,
+ /* 1 */ 0, 0, 0,
+ /* 2 */ 0, 0, 0,
+ /* 3 */ VK_CANCEL, 0, KEY_Break,
+ /* 4 */ 0, 0, 0,
+ /* 5 */ 0, 0, 0,
+ /* 6 */ 0, 0, 0,
+ /* 7 */ 0, 0, 0,
+ /* 8 */ 0, 0, 0,
+ /* 9 */ 0, 0, 0,
+ /* 10 */ 0, 0, 0,
+ /* 11 */ 0, 0, 0,
+ /* 12 */ 0, 0, 0,
+ /* 13 */ VK_RETURN, 0, KEY_KP_Enter,
+ /* 14 */ 0, 0, 0,
+ /* 15 */ 0, 0, 0,
+ /* 16 */ VK_SHIFT, 0, 0,
+ /* 17 */ VK_CONTROL, 0, KEY_RCtrl,
+ /* 18 */ VK_MENU, 0, KEY_AltLang,
+ /* 19 */ VK_PAUSE, KEY_Pause, 0,
+ /* 20 */ 0, 0, 0,
+ /* 21 */ 0, 0, 0,
+ /* 22 */ 0, 0, 0,
+ /* 23 */ 0, 0, 0,
+ /* 24 */ 0, 0, 0,
+ /* 25 */ 0, 0, 0,
+ /* 26 */ 0, 0, 0,
+ /* 27 */ 0, 0, 0,
+ /* 28 */ 0, 0, 0,
+ /* 29 */ 0, 0, 0,
+ /* 30 */ 0, 0, 0,
+ /* 31 */ 0, 0, 0,
+ /* 32 */ 0, 0, 0,
+ /* 33 */ VK_PRIOR, KEY_PgUp, KEY_PgUp,
+ /* 34 */ VK_NEXT, KEY_PgDown, KEY_PgDown,
+ /* 35 */ VK_END, KEY_End, KEY_End,
+ /* 36 */ VK_HOME, KEY_Home, KEY_Home,
+ /* 37 */ VK_LEFT, KEY_Left, KEY_Left,
+ /* 38 */ VK_UP, KEY_Up, KEY_Up,
+ /* 39 */ VK_RIGHT, KEY_Right, KEY_Right,
+ /* 40 */ VK_DOWN, KEY_Down, KEY_Down,
+ /* 41 */ 0, 0, 0,
+ /* 42 */ 0, 0, 0,
+ /* 43 */ 0, 0, 0,
+ /* 44 */ VK_SNAPSHOT, 0, KEY_Print,
+ /* 45 */ VK_INSERT, 0, KEY_Insert,
+ /* 46 */ VK_DELETE, 0, KEY_Delete,
+ /* 47 */ 0, 0, 0,
+ /* 48 */ 0, 0, 0,
+ /* 49 */ 0, 0, 0,
+ /* 50 */ 0, 0, 0,
+ /* 51 */ 0, 0, 0,
+ /* 52 */ 0, 0, 0,
+ /* 53 */ 0, 0, 0,
+ /* 54 */ 0, 0, 0,
+ /* 55 */ 0, 0, 0,
+ /* 56 */ 0, 0, 0,
+ /* 57 */ 0, 0, 0,
+ /* 58 */ 0, 0, 0,
+ /* 59 */ 0, 0, 0,
+ /* 60 */ 0, 0, 0,
+ /* 61 */ 0, 0, 0,
+ /* 62 */ 0, 0, 0,
+ /* 63 */ 0, 0, 0,
+ /* 64 */ 0, 0, 0,
+ /* 65 */ 0, 0, 0,
+ /* 66 */ 0, 0, 0,
+ /* 67 */ 0, 0, 0,
+ /* 68 */ 0, 0, 0,
+ /* 69 */ 0, 0, 0,
+ /* 70 */ 0, 0, 0,
+ /* 71 */ 0, 0, 0,
+ /* 72 */ 0, 0, 0,
+ /* 73 */ 0, 0, 0,
+ /* 74 */ 0, 0, 0,
+ /* 75 */ 0, 0, 0,
+ /* 76 */ 0, 0, 0,
+ /* 77 */ 0, 0, 0,
+ /* 78 */ 0, 0, 0,
+ /* 79 */ 0, 0, 0,
+ /* 80 */ 0, 0, 0,
+ /* 81 */ 0, 0, 0,
+ /* 82 */ 0, 0, 0,
+ /* 83 */ 0, 0, 0,
+ /* 84 */ 0, 0, 0,
+ /* 85 */ 0, 0, 0,
+ /* 86 */ 0, 0, 0,
+ /* 87 */ 0, 0, 0,
+ /* 88 */ 0, 0, 0,
+ /* 89 */ 0, 0, 0,
+ /* 90 */ 0, 0, 0,
+ /* 91 */ VK_LWIN, KEY_LMeta, 0,
+ /* 92 */ VK_RWIN, KEY_RMeta, 0,
+ /* 93 */ VK_APPS, KEY_Menu, 0,
+ /* 94 */ 0, 0, 0,
+ /* 95 */ 0, 0, 0,
+ /* 96 */ 0, 0, 0,
+ /* 97 */ 0, 0, 0,
+ /* 98 */ 0, 0, 0,
+ /* 99 */ 0, 0, 0,
+ /* 100 */ 0, 0, 0,
+ /* 101 */ 0, 0, 0,
+ /* 102 */ 0, 0, 0,
+ /* 103 */ 0, 0, 0,
+ /* 104 */ 0, 0, 0,
+ /* 105 */ 0, 0, 0,
+ /* 106 */ 0, 0, 0,
+ /* 107 */ 0, 0, 0,
+ /* 108 */ 0, 0, 0,
+ /* 109 */ 0, 0, 0,
+ /* 110 */ 0, 0, 0,
+ /* 111 */ VK_DIVIDE, 0, KEY_KP_Divide,
+ /* 112 */ 0, 0, 0,
+ /* 113 */ 0, 0, 0,
+ /* 114 */ 0, 0, 0,
+ /* 115 */ 0, 0, 0,
+ /* 116 */ 0, 0, 0,
+ /* 117 */ 0, 0, 0,
+ /* 118 */ 0, 0, 0,
+ /* 119 */ 0, 0, 0,
+ /* 120 */ 0, 0, 0,
+ /* 121 */ 0, 0, 0,
+ /* 122 */ 0, 0, 0,
+ /* 123 */ 0, 0, 0,
+ /* 124 */ 0, 0, 0,
+ /* 125 */ 0, 0, 0,
+ /* 126 */ 0, 0, 0,
+ /* 127 */ 0, 0, 0,
+ /* 128 */ 0, 0, 0,
+ /* 129 */ 0, 0, 0,
+ /* 130 */ 0, 0, 0,
+ /* 131 */ 0, 0, 0,
+ /* 132 */ 0, 0, 0,
+ /* 133 */ 0, 0, 0,
+ /* 134 */ 0, 0, 0,
+ /* 135 */ 0, 0, 0,
+ /* 136 */ 0, 0, 0,
+ /* 137 */ 0, 0, 0,
+ /* 138 */ 0, 0, 0,
+ /* 139 */ 0, 0, 0,
+ /* 140 */ 0, 0, 0,
+ /* 141 */ 0, 0, 0,
+ /* 142 */ 0, 0, 0,
+ /* 143 */ 0, 0, 0,
+ /* 144 */ 0, 0, 0,
+ /* 145 */ 0, 0, 0,
+ /* 146 */ 0, 0, 0,
+ /* 147 */ 0, 0, 0,
+ /* 148 */ 0, 0, 0,
+ /* 149 */ 0, 0, 0,
+ /* 150 */ 0, 0, 0,
+ /* 151 */ 0, 0, 0,
+ /* 152 */ 0, 0, 0,
+ /* 153 */ 0, 0, 0,
+ /* 154 */ 0, 0, 0,
+ /* 155 */ 0, 0, 0,
+ /* 156 */ 0, 0, 0,
+ /* 157 */ 0, 0, 0,
+ /* 158 */ 0, 0, 0,
+ /* 159 */ 0, 0, 0,
+ /* 160 */ VK_LSHIFT, KEY_ShiftL, KEY_ShiftL,
+ /* 161 */ VK_RSHIFT, KEY_ShiftR, KEY_ShiftR,
+ /* 162 */ VK_LCONTROL, KEY_LCtrl, KEY_LCtrl,
+ /* 163 */ VK_RCONTROL, KEY_RCtrl, KEY_RCtrl,
+ /* 164 */ VK_LMENU, KEY_Alt, KEY_Alt,
+ /* 165 */ VK_RMENU, KEY_AltLang, KEY_AltLang,
+ /* 166 */ 0, 0, 0,
+ /* 167 */ 0, 0, 0,
+ /* 168 */ 0, 0, 0,
+ /* 169 */ 0, 0, 0,
+ /* 170 */ 0, 0, 0,
+ /* 171 */ 0, 0, 0,
+ /* 172 */ 0, 0, 0,
+ /* 173 */ 0, 0, 0,
+ /* 174 */ 0, 0, 0,
+ /* 175 */ 0, 0, 0,
+ /* 176 */ 0, 0, 0,
+ /* 177 */ 0, 0, 0,
+ /* 178 */ 0, 0, 0,
+ /* 179 */ 0, 0, 0,
+ /* 180 */ 0, 0, 0,
+ /* 181 */ 0, 0, 0,
+ /* 182 */ 0, 0, 0,
+ /* 183 */ 0, 0, 0,
+ /* 184 */ 0, 0, 0,
+ /* 185 */ 0, 0, 0,
+ /* 186 */ 0, 0, 0,
+ /* 187 */ 0, 0, 0,
+ /* 188 */ 0, 0, 0,
+ /* 189 */ 0, 0, 0,
+ /* 190 */ 0, 0, 0,
+ /* 191 */ 0, 0, 0,
+ /* 192 */ 0, 0, 0,
+ /* 193 */ 0, 0, 0,
+ /* 194 */ 0, 0, 0,
+ /* 195 */ 0, 0, 0,
+ /* 196 */ 0, 0, 0,
+ /* 197 */ 0, 0, 0,
+ /* 198 */ 0, 0, 0,
+ /* 199 */ 0, 0, 0,
+ /* 200 */ 0, 0, 0,
+ /* 201 */ 0, 0, 0,
+ /* 202 */ 0, 0, 0,
+ /* 203 */ 0, 0, 0,
+ /* 204 */ 0, 0, 0,
+ /* 205 */ 0, 0, 0,
+ /* 206 */ 0, 0, 0,
+ /* 207 */ 0, 0, 0,
+ /* 208 */ 0, 0, 0,
+ /* 209 */ 0, 0, 0,
+ /* 210 */ 0, 0, 0,
+ /* 211 */ 0, 0, 0,
+ /* 212 */ 0, 0, 0,
+ /* 213 */ 0, 0, 0,
+ /* 214 */ 0, 0, 0,
+ /* 215 */ 0, 0, 0,
+ /* 216 */ 0, 0, 0,
+ /* 217 */ 0, 0, 0,
+ /* 218 */ 0, 0, 0,
+ /* 219 */ 0, 0, 0,
+ /* 220 */ 0, 0, 0,
+ /* 221 */ 0, 0, 0,
+ /* 222 */ 0, 0, 0,
+ /* 223 */ 0, 0, 0,
+ /* 224 */ 0, 0, 0,
+ /* 225 */ 0, 0, 0,
+ /* 226 */ 0, 0, 0,
+ /* 227 */ 0, 0, 0,
+ /* 228 */ 0, 0, 0,
+ /* 229 */ 0, 0, 0,
+ /* 230 */ 0, 0, 0,
+ /* 231 */ 0, 0, 0,
+ /* 232 */ 0, 0, 0,
+ /* 233 */ 0, 0, 0,
+ /* 234 */ 0, 0, 0,
+ /* 235 */ 0, 0, 0,
+ /* 236 */ 0, 0, 0,
+ /* 237 */ 0, 0, 0,
+ /* 238 */ 0, 0, 0,
+ /* 239 */ 0, 0, 0,
+ /* 240 */ 0, 0, 0,
+ /* 241 */ 0, 0, 0,
+ /* 242 */ 0, 0, 0,
+ /* 243 */ 0, 0, 0,
+ /* 244 */ 0, 0, 0,
+ /* 245 */ 0, 0, 0,
+ /* 246 */ 0, 0, 0,
+ /* 247 */ 0, 0, 0,
+ /* 248 */ 0, 0, 0,
+ /* 249 */ 0, 0, 0,
+ /* 250 */ 0, 0, 0,
+ /* 251 */ 0, 0, 0,
+ /* 252 */ 0, 0, 0,
+ /* 253 */ 0, 0, 0,
+ /* 254 */ 0, 0, 0,
+ /* 255 */ 0, 0, 0
+};
+
+#endif /* WINKEYBD_H */
diff --git a/xorg-server/hw/xwin/winmouse.c b/xorg-server/hw/xwin/winmouse.c index 835c69d50..c5069d630 100644 --- a/xorg-server/hw/xwin/winmouse.c +++ b/xorg-server/hw/xwin/winmouse.c @@ -1,385 +1,385 @@ -/* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of the XFree86 Project - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from the XFree86 Project. - * - * Authors: Dakshinamurthy Karra - * Suhaib M Siddiqi - * Peter Busch - * Harold L Hunt II - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" - -#ifdef XKB -#ifndef XKB_IN_SERVER -#define XKB_IN_SERVER -#endif -#include <xkbsrv.h> -#endif - -#include "inputstr.h" -#include "exevents.h" /* for button/axes labels */ -#include "xserver-properties.h" - -/* Peek the internal button mapping */ -static CARD8 const *g_winMouseButtonMap = NULL; - - -/* - * Local prototypes - */ - -static void -winMouseCtrl (DeviceIntPtr pDevice, PtrCtrl *pCtrl); - - -static void -winMouseCtrl (DeviceIntPtr pDevice, PtrCtrl *pCtrl) -{ -} - - -/* - * See Porting Layer Definition - p. 18 - * This is known as a DeviceProc - */ - -int -winMouseProc (DeviceIntPtr pDeviceInt, int iState) -{ - int lngMouseButtons, i; - int lngWheelEvents = 2; - CARD8 *map; - DevicePtr pDevice = (DevicePtr) pDeviceInt; - Atom *btn_labels; - Atom axes_labels[2]; - - switch (iState) - { - case DEVICE_INIT: - /* Get number of mouse buttons */ - lngMouseButtons = GetSystemMetrics(SM_CMOUSEBUTTONS); - - /* Mapping of windows events to X events: - * LEFT:1 MIDDLE:2 RIGHT:3 - * SCROLL_UP:4 SCROLL_DOWN:5 - * XBUTTON 1:6 XBUTTON 2:7 ... - * - * To map scroll wheel correctly we need at least the 3 normal buttons - */ - if (lngMouseButtons < 3) - lngMouseButtons = 3; - winDebug("%d mouse buttons found\n", lngMouseButtons); - - /* allocate memory: - * number of buttons + 2x mouse wheel event + 1 extra (offset for map) - */ - map = malloc(sizeof(CARD8) * (lngMouseButtons + lngWheelEvents + 1)); - - /* initalize button map */ - map[0] = 0; - for (i=1; i <= lngMouseButtons + lngWheelEvents; i++) - map[i] = i; - - btn_labels = calloc((lngMouseButtons + lngWheelEvents), sizeof(Atom)); - btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT); - btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE); - btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT); - btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP); - btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN); - - axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X); - axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y); - - InitPointerDeviceStruct (pDevice, - map, - lngMouseButtons + lngWheelEvents, - btn_labels, - winMouseCtrl, - GetMotionHistorySize(), - 2, - axes_labels); - free(map); - free(btn_labels); - - g_winMouseButtonMap = pDeviceInt->button->map; - break; - - case DEVICE_ON: - pDevice->on = TRUE; - break; - - case DEVICE_CLOSE: - g_winMouseButtonMap = NULL; - case DEVICE_OFF: - pDevice->on = FALSE; - break; - } - return Success; -} - - -/* Handle the mouse wheel */ -int -winMouseWheel (ScreenPtr pScreen, int iDeltaZ) -{ - winScreenPriv(pScreen); - int button; /* Button4 or Button5 */ - - /* Button4 = WheelUp */ - /* Button5 = WheelDown */ - - /* Do we have any previous delta stored? */ - if ((pScreenPriv->iDeltaZ > 0 - && iDeltaZ > 0) - || (pScreenPriv->iDeltaZ < 0 - && iDeltaZ < 0)) - { - /* Previous delta and of same sign as current delta */ - iDeltaZ += pScreenPriv->iDeltaZ; - pScreenPriv->iDeltaZ = 0; - } - else - { - /* - * Previous delta of different sign, or zero. - * We will set it to zero for either case, - * as blindly setting takes just as much time - * as checking, then setting if necessary :) - */ - pScreenPriv->iDeltaZ = 0; - } - - /* - * Only process this message if the wheel has moved further than - * WHEEL_DELTA - */ - if (iDeltaZ >= WHEEL_DELTA || (-1 * iDeltaZ) >= WHEEL_DELTA) - { - pScreenPriv->iDeltaZ = 0; - - /* Figure out how many whole deltas of the wheel we have */ - iDeltaZ /= WHEEL_DELTA; - } - else - { - /* - * Wheel has not moved past WHEEL_DELTA threshold; - * we will store the wheel delta until the threshold - * has been reached. - */ - pScreenPriv->iDeltaZ = iDeltaZ; - return 0; - } - - /* Set the button to indicate up or down wheel delta */ - if (iDeltaZ > 0) - { - button = Button4; - } - else - { - button = Button5; - } - - /* - * Flip iDeltaZ to positive, if negative, - * because always need to generate a *positive* number of - * button clicks for the Z axis. - */ - if (iDeltaZ < 0) - { - iDeltaZ *= -1; - } - - /* Generate X input messages for each wheel delta we have seen */ - while (iDeltaZ--) - { - /* Push the wheel button */ - winMouseButtonsSendEvent (ButtonPress, button); - - /* Release the wheel button */ - winMouseButtonsSendEvent (ButtonRelease, button); - } - - return 0; -} - - -/* - * Enqueue a mouse button event - */ - -void -winMouseButtonsSendEvent (int iEventType, int iButton) -{ - EventListPtr events; - int i, nevents; - - if (g_winMouseButtonMap) - iButton = g_winMouseButtonMap[iButton]; - - GetEventList(&events); - nevents = GetPointerEvents(events, g_pwinPointer, iEventType, iButton, - POINTER_RELATIVE, 0, 0, NULL); - - for (i = 0; i < nevents; i++) - mieqEnqueue(g_pwinPointer, (InternalEvent*)(events + i)->event); - - winDebug("winMouseButtonsSendEvent: iEventType: %d, iButton: %d, nEvents %d\n", - iEventType, iButton, nevents); -} - - -/* - * Decide what to do with a Windows mouse message - */ - -int -winMouseButtonsHandle (ScreenPtr pScreen, - int iEventType, int iButton, - WPARAM wParam) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - - /* Send button events right away if emulate 3 buttons is off */ - if (pScreenInfo->iE3BTimeout == WIN_E3B_OFF) - { - /* Emulate 3 buttons is off, send the button event */ - winMouseButtonsSendEvent (iEventType, iButton); - return 0; - } - - /* Emulate 3 buttons is on, let the fun begin */ - if (iEventType == ButtonPress - && pScreenPriv->iE3BCachedPress == 0 - && !pScreenPriv->fE3BFakeButton2Sent) - { - /* - * Button was pressed, no press is cached, - * and there is no fake button 2 release pending. - */ - - /* Store button press type */ - pScreenPriv->iE3BCachedPress = iButton; - - /* - * Set a timer to send this button press if the other button - * is not pressed within the timeout time. - */ - SetTimer (pScreenPriv->hwndScreen, - WIN_E3B_TIMER_ID, - pScreenInfo->iE3BTimeout, - NULL); - } - else if (iEventType == ButtonPress - && pScreenPriv->iE3BCachedPress != 0 - && pScreenPriv->iE3BCachedPress != iButton - && !pScreenPriv->fE3BFakeButton2Sent) - { - /* - * Button press is cached, other button was pressed, - * and there is no fake button 2 release pending. - */ - - /* Mouse button was cached and other button was pressed */ - KillTimer (pScreenPriv->hwndScreen, WIN_E3B_TIMER_ID); - pScreenPriv->iE3BCachedPress = 0; - - /* Send fake middle button */ - winMouseButtonsSendEvent (ButtonPress, Button2); - - /* Indicate that a fake middle button event was sent */ - pScreenPriv->fE3BFakeButton2Sent = TRUE; - } - else if (iEventType == ButtonRelease - && pScreenPriv->iE3BCachedPress == iButton) - { - /* - * Cached button was released before timer ran out, - * and before the other mouse button was pressed. - */ - KillTimer (pScreenPriv->hwndScreen, WIN_E3B_TIMER_ID); - pScreenPriv->iE3BCachedPress = 0; - - /* Send cached press, then send release */ - winMouseButtonsSendEvent (ButtonPress, iButton); - winMouseButtonsSendEvent (ButtonRelease, iButton); - } - else if (iEventType == ButtonRelease - && pScreenPriv->fE3BFakeButton2Sent - && !(wParam & MK_LBUTTON) - && !(wParam & MK_RBUTTON)) - { - /* - * Fake button 2 was sent and both mouse buttons have now been released - */ - pScreenPriv->fE3BFakeButton2Sent = FALSE; - - /* Send middle mouse button release */ - winMouseButtonsSendEvent (ButtonRelease, Button2); - } - else if (iEventType == ButtonRelease - && pScreenPriv->iE3BCachedPress == 0 - && !pScreenPriv->fE3BFakeButton2Sent) - { - /* - * Button was release, no button is cached, - * and there is no fake button 2 release is pending. - */ - winMouseButtonsSendEvent (ButtonRelease, iButton); - } - - return 0; -} - -/** - * Enqueue a motion event. - * - * XXX: miPointerMove does exactly this, but is static :-( (and uses a static buffer) - * - */ -void winEnqueueMotion(int x, int y) -{ - int i, nevents; - int valuators[2]; - EventListPtr events; - - miPointerSetPosition(g_pwinPointer, &x, &y); - valuators[0] = x; - valuators[1] = y; - - GetEventList(&events); - nevents = GetPointerEvents(events, g_pwinPointer, MotionNotify, 0, - POINTER_ABSOLUTE, 0, 2, valuators); - - for (i = 0; i < nevents; i++) - mieqEnqueue(g_pwinPointer, (InternalEvent*)(events + i)->event); -} +/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Dakshinamurthy Karra
+ * Suhaib M Siddiqi
+ * Peter Busch
+ * Harold L Hunt II
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+
+#ifdef XKB
+#ifndef XKB_IN_SERVER
+#define XKB_IN_SERVER
+#endif
+#include <xkbsrv.h>
+#endif
+
+#include "inputstr.h"
+#include "exevents.h" /* for button/axes labels */
+#include "xserver-properties.h"
+
+/* Peek the internal button mapping */
+static CARD8 const *g_winMouseButtonMap = NULL;
+
+
+/*
+ * Local prototypes
+ */
+
+static void
+winMouseCtrl (DeviceIntPtr pDevice, PtrCtrl *pCtrl);
+
+
+static void
+winMouseCtrl (DeviceIntPtr pDevice, PtrCtrl *pCtrl)
+{
+}
+
+
+/*
+ * See Porting Layer Definition - p. 18
+ * This is known as a DeviceProc
+ */
+
+int
+winMouseProc (DeviceIntPtr pDeviceInt, int iState)
+{
+ int lngMouseButtons, i;
+ int lngWheelEvents = 2;
+ CARD8 *map;
+ DevicePtr pDevice = (DevicePtr) pDeviceInt;
+ Atom *btn_labels;
+ Atom axes_labels[2];
+
+ switch (iState)
+ {
+ case DEVICE_INIT:
+ /* Get number of mouse buttons */
+ lngMouseButtons = GetSystemMetrics(SM_CMOUSEBUTTONS);
+
+ /* Mapping of windows events to X events:
+ * LEFT:1 MIDDLE:2 RIGHT:3
+ * SCROLL_UP:4 SCROLL_DOWN:5
+ * XBUTTON 1:6 XBUTTON 2:7 ...
+ *
+ * To map scroll wheel correctly we need at least the 3 normal buttons
+ */
+ if (lngMouseButtons < 3)
+ lngMouseButtons = 3;
+ winDebug("%d mouse buttons found\n", lngMouseButtons);
+
+ /* allocate memory:
+ * number of buttons + 2x mouse wheel event + 1 extra (offset for map)
+ */
+ map = malloc(sizeof(CARD8) * (lngMouseButtons + lngWheelEvents + 1));
+
+ /* initalize button map */
+ map[0] = 0;
+ for (i=1; i <= lngMouseButtons + lngWheelEvents; i++)
+ map[i] = i;
+
+ btn_labels = calloc((lngMouseButtons + lngWheelEvents), sizeof(Atom));
+ btn_labels[0] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_LEFT);
+ btn_labels[1] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_MIDDLE);
+ btn_labels[2] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_RIGHT);
+ btn_labels[3] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_UP);
+ btn_labels[4] = XIGetKnownProperty(BTN_LABEL_PROP_BTN_WHEEL_DOWN);
+
+ axes_labels[0] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_X);
+ axes_labels[1] = XIGetKnownProperty(AXIS_LABEL_PROP_REL_Y);
+
+ InitPointerDeviceStruct (pDevice,
+ map,
+ lngMouseButtons + lngWheelEvents,
+ btn_labels,
+ winMouseCtrl,
+ GetMotionHistorySize(),
+ 2,
+ axes_labels);
+ free(map);
+ free(btn_labels);
+
+ g_winMouseButtonMap = pDeviceInt->button->map;
+ break;
+
+ case DEVICE_ON:
+ pDevice->on = TRUE;
+ break;
+
+ case DEVICE_CLOSE:
+ g_winMouseButtonMap = NULL;
+ case DEVICE_OFF:
+ pDevice->on = FALSE;
+ break;
+ }
+ return Success;
+}
+
+
+/* Handle the mouse wheel */
+int
+winMouseWheel (ScreenPtr pScreen, int iDeltaZ)
+{
+ winScreenPriv(pScreen);
+ int button; /* Button4 or Button5 */
+
+ /* Button4 = WheelUp */
+ /* Button5 = WheelDown */
+
+ /* Do we have any previous delta stored? */
+ if ((pScreenPriv->iDeltaZ > 0
+ && iDeltaZ > 0)
+ || (pScreenPriv->iDeltaZ < 0
+ && iDeltaZ < 0))
+ {
+ /* Previous delta and of same sign as current delta */
+ iDeltaZ += pScreenPriv->iDeltaZ;
+ pScreenPriv->iDeltaZ = 0;
+ }
+ else
+ {
+ /*
+ * Previous delta of different sign, or zero.
+ * We will set it to zero for either case,
+ * as blindly setting takes just as much time
+ * as checking, then setting if necessary :)
+ */
+ pScreenPriv->iDeltaZ = 0;
+ }
+
+ /*
+ * Only process this message if the wheel has moved further than
+ * WHEEL_DELTA
+ */
+ if (iDeltaZ >= WHEEL_DELTA || (-1 * iDeltaZ) >= WHEEL_DELTA)
+ {
+ pScreenPriv->iDeltaZ = 0;
+
+ /* Figure out how many whole deltas of the wheel we have */
+ iDeltaZ /= WHEEL_DELTA;
+ }
+ else
+ {
+ /*
+ * Wheel has not moved past WHEEL_DELTA threshold;
+ * we will store the wheel delta until the threshold
+ * has been reached.
+ */
+ pScreenPriv->iDeltaZ = iDeltaZ;
+ return 0;
+ }
+
+ /* Set the button to indicate up or down wheel delta */
+ if (iDeltaZ > 0)
+ {
+ button = Button4;
+ }
+ else
+ {
+ button = Button5;
+ }
+
+ /*
+ * Flip iDeltaZ to positive, if negative,
+ * because always need to generate a *positive* number of
+ * button clicks for the Z axis.
+ */
+ if (iDeltaZ < 0)
+ {
+ iDeltaZ *= -1;
+ }
+
+ /* Generate X input messages for each wheel delta we have seen */
+ while (iDeltaZ--)
+ {
+ /* Push the wheel button */
+ winMouseButtonsSendEvent (ButtonPress, button);
+
+ /* Release the wheel button */
+ winMouseButtonsSendEvent (ButtonRelease, button);
+ }
+
+ return 0;
+}
+
+
+/*
+ * Enqueue a mouse button event
+ */
+
+void
+winMouseButtonsSendEvent (int iEventType, int iButton)
+{
+ EventListPtr events;
+ int i, nevents;
+
+ if (g_winMouseButtonMap)
+ iButton = g_winMouseButtonMap[iButton];
+
+ GetEventList(&events);
+ nevents = GetPointerEvents(events, g_pwinPointer, iEventType, iButton,
+ POINTER_RELATIVE, 0, 0, NULL);
+
+ for (i = 0; i < nevents; i++)
+ mieqEnqueue(g_pwinPointer, (InternalEvent*)(events + i)->event);
+
+ winDebug("winMouseButtonsSendEvent: iEventType: %d, iButton: %d, nEvents %d\n",
+ iEventType, iButton, nevents);
+}
+
+
+/*
+ * Decide what to do with a Windows mouse message
+ */
+
+int
+winMouseButtonsHandle (ScreenPtr pScreen,
+ int iEventType, int iButton,
+ WPARAM wParam)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+
+ /* Send button events right away if emulate 3 buttons is off */
+ if (pScreenInfo->iE3BTimeout == WIN_E3B_OFF)
+ {
+ /* Emulate 3 buttons is off, send the button event */
+ winMouseButtonsSendEvent (iEventType, iButton);
+ return 0;
+ }
+
+ /* Emulate 3 buttons is on, let the fun begin */
+ if (iEventType == ButtonPress
+ && pScreenPriv->iE3BCachedPress == 0
+ && !pScreenPriv->fE3BFakeButton2Sent)
+ {
+ /*
+ * Button was pressed, no press is cached,
+ * and there is no fake button 2 release pending.
+ */
+
+ /* Store button press type */
+ pScreenPriv->iE3BCachedPress = iButton;
+
+ /*
+ * Set a timer to send this button press if the other button
+ * is not pressed within the timeout time.
+ */
+ SetTimer (pScreenPriv->hwndScreen,
+ WIN_E3B_TIMER_ID,
+ pScreenInfo->iE3BTimeout,
+ NULL);
+ }
+ else if (iEventType == ButtonPress
+ && pScreenPriv->iE3BCachedPress != 0
+ && pScreenPriv->iE3BCachedPress != iButton
+ && !pScreenPriv->fE3BFakeButton2Sent)
+ {
+ /*
+ * Button press is cached, other button was pressed,
+ * and there is no fake button 2 release pending.
+ */
+
+ /* Mouse button was cached and other button was pressed */
+ KillTimer (pScreenPriv->hwndScreen, WIN_E3B_TIMER_ID);
+ pScreenPriv->iE3BCachedPress = 0;
+
+ /* Send fake middle button */
+ winMouseButtonsSendEvent (ButtonPress, Button2);
+
+ /* Indicate that a fake middle button event was sent */
+ pScreenPriv->fE3BFakeButton2Sent = TRUE;
+ }
+ else if (iEventType == ButtonRelease
+ && pScreenPriv->iE3BCachedPress == iButton)
+ {
+ /*
+ * Cached button was released before timer ran out,
+ * and before the other mouse button was pressed.
+ */
+ KillTimer (pScreenPriv->hwndScreen, WIN_E3B_TIMER_ID);
+ pScreenPriv->iE3BCachedPress = 0;
+
+ /* Send cached press, then send release */
+ winMouseButtonsSendEvent (ButtonPress, iButton);
+ winMouseButtonsSendEvent (ButtonRelease, iButton);
+ }
+ else if (iEventType == ButtonRelease
+ && pScreenPriv->fE3BFakeButton2Sent
+ && !(wParam & MK_LBUTTON)
+ && !(wParam & MK_RBUTTON))
+ {
+ /*
+ * Fake button 2 was sent and both mouse buttons have now been released
+ */
+ pScreenPriv->fE3BFakeButton2Sent = FALSE;
+
+ /* Send middle mouse button release */
+ winMouseButtonsSendEvent (ButtonRelease, Button2);
+ }
+ else if (iEventType == ButtonRelease
+ && pScreenPriv->iE3BCachedPress == 0
+ && !pScreenPriv->fE3BFakeButton2Sent)
+ {
+ /*
+ * Button was release, no button is cached,
+ * and there is no fake button 2 release is pending.
+ */
+ winMouseButtonsSendEvent (ButtonRelease, iButton);
+ }
+
+ return 0;
+}
+
+/**
+ * Enqueue a motion event.
+ *
+ * XXX: miPointerMove does exactly this, but is static :-( (and uses a static buffer)
+ *
+ */
+void winEnqueueMotion(int x, int y)
+{
+ int i, nevents;
+ int valuators[2];
+ EventListPtr events;
+
+ miPointerSetPosition(g_pwinPointer, &x, &y);
+ valuators[0] = x;
+ valuators[1] = y;
+
+ GetEventList(&events);
+ nevents = GetPointerEvents(events, g_pwinPointer, MotionNotify, 0,
+ POINTER_ABSOLUTE | POINTER_SCREEN, 0, 2, valuators);
+
+ for (i = 0; i < nevents; i++)
+ mieqEnqueue(g_pwinPointer, (InternalEvent*)(events + i)->event);
+}
diff --git a/xorg-server/hw/xwin/winmultiwindowicons.c b/xorg-server/hw/xwin/winmultiwindowicons.c index ea1814b61..89acf72be 100644 --- a/xorg-server/hw/xwin/winmultiwindowicons.c +++ b/xorg-server/hw/xwin/winmultiwindowicons.c @@ -1,647 +1,649 @@ -/* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of the XFree86 Project - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from the XFree86 Project. - * - * Authors: Earle F. Philhower, III - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" -#include "dixevents.h" -#include "winmultiwindowclass.h" -#include "winprefs.h" - -#include "propertyst.h" - -#include "propertyst.h" -#include "windowstr.h" - -/* - * External global variables - */ - -extern HICON g_hIconX; -extern HICON g_hSmallIconX; - - -/* - * Prototypes for local functions - */ - -static void -winScaleXBitmapToWindows (int iconSize, int effBPP, - PixmapPtr pixmap, unsigned char *image); - - -/* - * Scale an X icon bitmap into a Windoze icon bitmap - */ - -static void -winScaleXBitmapToWindows (int iconSize, - int effBPP, - PixmapPtr pixmap, - unsigned char *image) -{ - int row, column, effXBPP, effXDepth; - unsigned char *outPtr; - char *iconData = 0; - int stride, xStride; - float factX, factY; - int posX, posY; - unsigned char *ptr; - unsigned int zero; - unsigned int color; - - effXBPP = BitsPerPixel(pixmap->drawable.depth); - effXDepth = pixmap->drawable.depth; - - if (pixmap->drawable.bitsPerPixel == 15) - effXBPP = 16; - - if (pixmap->drawable.depth == 15) - effXDepth = 16; - - /* Need 16-bit aligned rows for DDBitmaps */ - stride = ((iconSize * effBPP + 15) & (~15)) / 8; - xStride = PixmapBytePad (pixmap->drawable.width, pixmap->drawable.depth); - if (stride == 0 || xStride == 0) - { - ErrorF ("winScaleXBitmapToWindows - stride or xStride is zero. " - "Bailing.\n"); - return; - } - - /* Allocate memory for icon data */ - iconData = malloc (xStride * pixmap->drawable.height); - if (!iconData) - { - ErrorF ("winScaleXBitmapToWindows - malloc failed for iconData. " - "Bailing.\n"); - return; - } - - /* Get icon data */ - miGetImage ((DrawablePtr) &(pixmap->drawable), 0, 0, - pixmap->drawable.width, pixmap->drawable.height, - ZPixmap, 0xffffffff, iconData); - - /* Keep aspect ratio */ - factX = ((float)pixmap->drawable.width) / ((float)iconSize); - factY = ((float)pixmap->drawable.height) / ((float)iconSize); - if (factX > factY) - factY = factX; - else - factX = factY; - - /* Out-of-bounds, fill icon with zero */ - zero = 0; - - for (row = 0; row < iconSize; row++) - { - outPtr = image + stride * row; - for (column = 0; column < iconSize; column++) - { - posX = factX * column; - posY = factY * row; - - ptr = (unsigned char*) iconData + posY*xStride; - if (effXBPP == 1) - { - ptr += posX / 8; - - /* Out of X icon bounds, leave space blank */ - if (posX >= pixmap->drawable.width - || posY >= pixmap->drawable.height) - ptr = (unsigned char *) &zero; - - if ((*ptr) & (1 << (posX & 7))) - switch (effBPP) - { - case 32: - *(outPtr++) = 0; - case 24: - *(outPtr++) = 0; - case 16: - *(outPtr++) = 0; - case 8: - *(outPtr++) = 0; - break; - case 1: - outPtr[column / 8] &= ~(1 << (7 - (column & 7))); - break; - } - else - switch (effBPP) - { - case 32: - *(outPtr++) = 255; - *(outPtr++) = 255; - *(outPtr++) = 255; - *(outPtr++) = 0; - break; - case 24: - *(outPtr++) = 255; - case 16: - *(outPtr++) = 255; - case 8: - *(outPtr++) = 255; - break; - case 1: - outPtr[column / 8] |= (1 << (7 - (column & 7))); - break; - } - } - else if (effXDepth == 24 || effXDepth == 32) - { - ptr += posX * (effXBPP / 8); - - /* Out of X icon bounds, leave space blank */ - if (posX >= pixmap->drawable.width - || posY >= pixmap->drawable.height) - ptr = (unsigned char *) &zero; - color = (((*ptr) << 16) - + ((*(ptr + 1)) << 8) - + ((*(ptr + 2)) << 0)); - switch (effBPP) - { - case 32: - *(outPtr++) = *(ptr++); /* b */ - *(outPtr++) = *(ptr++); /* g */ - *(outPtr++) = *(ptr++); /* r */ - *(outPtr++) = (effXDepth == 32) ? *(ptr++) : 0x0; /* alpha */ - break; - case 24: - *(outPtr++) = *(ptr++); - *(outPtr++) = *(ptr++); - *(outPtr++) = *(ptr++); - break; - case 16: - color = ((((*ptr) >> 2) << 10) - + (((*(ptr + 1)) >> 2) << 5) - + (((*(ptr + 2)) >> 2))); - *(outPtr++) = (color >> 8); - *(outPtr++) = (color & 255); - break; - case 8: - color = (((*ptr))) + (((*(ptr + 1)))) + (((*(ptr + 2)))); - color /= 3; - *(outPtr++) = color; - break; - case 1: - if (color) - outPtr[column / 8] |= (1 << (7 - (column & 7))); - else - outPtr[column / 8] &= ~(1 << (7 - (column & 7))); - } - } - else if (effXDepth == 16) - { - ptr += posX * (effXBPP / 8); - - /* Out of X icon bounds, leave space blank */ - if (posX >= pixmap->drawable.width - || posY >= pixmap->drawable.height) - ptr = (unsigned char *) &zero; - color = ((*ptr) << 8) + (*(ptr + 1)); - switch (effBPP) - { - case 32: - *(outPtr++) = (color & 31) << 2; - *(outPtr++) = ((color >> 5) & 31) << 2; - *(outPtr++) = ((color >> 10) & 31) << 2; - *(outPtr++) = 0; /* resvd */ - break; - case 24: - *(outPtr++) = (color & 31) << 2; - *(outPtr++) = ((color >> 5) & 31) << 2; - *(outPtr++) = ((color >> 10) & 31) << 2; - break; - case 16: - *(outPtr++) = *(ptr++); - *(outPtr++) = *(ptr++); - break; - case 8: - *(outPtr++) = (((color & 31) - + ((color >> 5) & 31) - + ((color >> 10) & 31)) / 3) << 2; - break; - case 1: - if (color) - outPtr[column / 8] |= (1 << (7 - (column & 7))); - else - outPtr[column / 8] &= ~(1 << (7 - (column & 7))); - break; - } /* end switch(effbpp) */ - } /* end if effxbpp==16) */ - } /* end for column */ - } /* end for row */ - free (iconData); -} - -static HICON -NetWMToWinIconAlpha(uint32_t *icon) -{ - int width = icon[0]; - int height = icon[1]; - uint32_t *pixels = &icon[2]; - HICON result; - HDC hdc = GetDC(NULL); - uint32_t *DIB_pixels; - ICONINFO ii = {TRUE}; - BITMAPV4HEADER bmh = {sizeof(bmh)}; - - /* Define an ARGB pixel format used for Color+Alpha icons */ - bmh.bV4Width = width; - bmh.bV4Height = -height; /* Invert the image */ - bmh.bV4Planes = 1; - bmh.bV4BitCount = 32; - bmh.bV4V4Compression = BI_BITFIELDS; - bmh.bV4AlphaMask = 0xFF000000; - bmh.bV4RedMask = 0x00FF0000; - bmh.bV4GreenMask = 0x0000FF00; - bmh.bV4BlueMask = 0x000000FF; - - ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh, - DIB_RGB_COLORS, (void**)&DIB_pixels, NULL, 0); - ReleaseDC(NULL, hdc); - ii.hbmMask = CreateBitmap(width, height, 1, 1, NULL); - memcpy(DIB_pixels, pixels, height*width*4); - - /* CreateIconIndirect() traditionally required DDBitmaps */ - /* Systems from WinXP accept 32-bit ARGB DIBitmaps with full 8-bit alpha support */ - /* The icon is created with a DIB + empty DDB mask (an MS example does the same) */ - result = CreateIconIndirect(&ii); - - DeleteObject(ii.hbmColor); - DeleteObject(ii.hbmMask); - - winDebug("NetWMToWinIconAlpha - %d x %d = %p\n", icon[0], icon[1], result); - return result; -} - -static HICON -NetWMToWinIconThreshold(uint32_t *icon) -{ - int width = icon[0]; - int height = icon[1]; - uint32_t *pixels = &icon[2]; - int row, col; - HICON result; - ICONINFO ii = {TRUE}; - - HDC hdc = GetDC(NULL); - HDC xorDC = CreateCompatibleDC(hdc); - HDC andDC = CreateCompatibleDC(hdc); - ii.hbmColor = CreateCompatibleBitmap(hdc, width, height); - ii.hbmMask = CreateCompatibleBitmap(hdc, width, height); - ReleaseDC(NULL, hdc); - SelectObject(xorDC, ii.hbmColor); - SelectObject(andDC, ii.hbmMask); - - for (row = 0; row < height; row++) { - for (col = 0; col < width; col++) { - if ((*pixels & 0xFF000000) > 31<<24) { /* 31 alpha threshold, i.e. opaque above, transparent below */ - SetPixelV(xorDC, col, row, RGB(((char*)pixels)[2], ((char*)pixels)[1], - ((char*)pixels)[0])); - SetPixelV(andDC, col, row, RGB(0, 0, 0)); /* black mask */ - } - else { - SetPixelV(xorDC, col, row, RGB(0, 0, 0)); - SetPixelV(andDC, col, row, RGB(255, 255, 255)); /* white mask */ - } - pixels++; - } - } - DeleteDC(xorDC); - DeleteDC(andDC); - - result = CreateIconIndirect(&ii); - - DeleteObject(ii.hbmColor); - DeleteObject(ii.hbmMask ); - - winDebug("NetWMToWinIconThreshold - %d x %d = %p\n", icon[0], icon[1], result); - return result; -} - -static HICON -NetWMToWinIcon(int bpp, uint32_t *icon) -{ - static Bool hasIconAlphaChannel = FALSE; - static BOOL versionChecked = FALSE; - - if (!versionChecked) - { - OSVERSIONINFOEX osvi = {0}; - ULONGLONG dwlConditionMask = 0; - - osvi.dwOSVersionInfoSize = sizeof (osvi); - osvi.dwMajorVersion = 5; - osvi.dwMinorVersion = 1; - - /* Windows versions later than XP have icon alpha channel suport, 2000 does not */ - VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); - VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); - hasIconAlphaChannel = VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask); - versionChecked = TRUE; - - winDebug("OS has icon alpha channel support: %s\n", hasIconAlphaChannel ? "yes" : "no"); - } - - if (hasIconAlphaChannel && (bpp==32)) - return NetWMToWinIconAlpha(icon); - else - return NetWMToWinIconThreshold(icon); -} - -static pointer -GetWindowProp(WindowPtr pWin, Atom name, long int *size_return) -{ - struct _Window *pwin; - struct _Property *prop; - - if (!pWin || !name) { - ErrorF ("GetWindowProp - pWin or name was NULL\n"); - return 0; - } - pwin = (struct _Window*) pWin; - if (!pwin->optional) return NULL; - for (prop = (struct _Property *) pwin->optional->userProps; - prop; - prop=prop->next){ - if (prop->propertyName == name) { - *size_return=prop->size; - return prop->data; - } - } - return NULL; -} - -/* - * Attempt to create a custom icon from the WM_HINTS bitmaps - */ - -HICON -winXIconToHICON (WindowPtr pWin, int iconSize) -{ - unsigned char *mask, *image, *imageMask; - unsigned char *dst, *src; - PixmapPtr iconPtr; - PixmapPtr maskPtr; - int planes, bpp, effBPP, stride, maskStride, i; - int biggest_size = 0; - HDC hDC; - ICONINFO ii; - WinXWMHints hints; - HICON hIcon = NULL; - uint32_t *biggest_icon = NULL; - - /* Try to get _NET_WM_ICON icons first */ - static Atom _XA_NET_WM_ICON; - static int generation; - uint32_t *icon, *icon_data = NULL; - long int size=0; - - hDC = GetDC (GetDesktopWindow ()); - planes = GetDeviceCaps (hDC, PLANES); - bpp = GetDeviceCaps (hDC, BITSPIXEL); - ReleaseDC (GetDesktopWindow (), hDC); - - if (generation != serverGeneration) { - generation = serverGeneration; - _XA_NET_WM_ICON = MakeAtom("_NET_WM_ICON", 12, TRUE); - } - - if (_XA_NET_WM_ICON) icon_data = GetWindowProp(pWin, _XA_NET_WM_ICON, &size); - if (icon_data) - { - for(icon = icon_data; - icon < &icon_data[size] && *icon; - icon = &icon[icon[0]*icon[1]+2]) - { - if (icon[0]==iconSize && icon[1]==iconSize) - return NetWMToWinIcon(bpp, icon); - /* Find the biggest icon and let Windows scale the size */ - else if (biggest_size < icon[0]) - { - biggest_icon = icon; - biggest_size = icon[0]; - } - } - if (biggest_icon) - return NetWMToWinIcon(bpp, biggest_icon); - } - winDebug("winXIconToHICON - pWin %x: no suitable NetIcon\n",(int)pWin, iconSize); - - winMultiWindowGetWMHints (pWin, &hints); - if (!hints.icon_pixmap) return NULL; - - iconPtr = (PixmapPtr) LookupIDByType (hints.icon_pixmap, RT_PIXMAP); - - if (!iconPtr) return NULL; - - /* 15 BPP is really 16BPP as far as we care */ - if (bpp == 15) - effBPP = 16; - else - effBPP = bpp; - - /* Need 16-bit aligned rows for DDBitmaps */ - stride = ((iconSize * effBPP + 15) & (~15)) / 8; - - /* Mask is 1-bit deep */ - maskStride = ((iconSize * 1 + 15) & (~15)) / 8; - - image = malloc (stride * iconSize); - imageMask = malloc (stride * iconSize); - /* Default to a completely black mask */ - mask = calloc (maskStride, iconSize); - - winScaleXBitmapToWindows (iconSize, effBPP, iconPtr, image); - maskPtr = (PixmapPtr) LookupIDByType (hints.icon_mask, RT_PIXMAP); - - if (maskPtr) - { - winScaleXBitmapToWindows (iconSize, 1, maskPtr, mask); - - winScaleXBitmapToWindows (iconSize, effBPP, maskPtr, imageMask); - - /* Now we need to set all bits of the icon which are not masked */ - /* on to 0 because Color is really an XOR, not an OR function */ - dst = image; - src = imageMask; - - for (i = 0; i < (stride * iconSize); i++) - if ((*(src++))) - *(dst++) = 0; - else - dst++; - } - - ii.fIcon = TRUE; - ii.xHotspot = 0; /* ignored */ - ii.yHotspot = 0; /* ignored */ - - /* Create Win32 mask from pixmap shape */ - ii.hbmMask = CreateBitmap (iconSize, iconSize, planes, 1, mask); - - /* Create Win32 bitmap from pixmap */ - ii.hbmColor = CreateBitmap (iconSize, iconSize, planes, bpp, image); - - /* Merge Win32 mask and bitmap into icon */ - hIcon = CreateIconIndirect (&ii); - - /* Release Win32 mask and bitmap */ - DeleteObject (ii.hbmMask); - DeleteObject (ii.hbmColor); - - /* Free X mask and bitmap */ - free (mask); - free (image); - free (imageMask); - - return hIcon; -} - - - -/* - * Change the Windows window icon - */ - -#ifdef XWIN_MULTIWINDOW -void -winUpdateIcon (Window id) -{ - WindowPtr pWin; - HICON hIcon, hIconSmall=NULL, hIconOld; - - pWin = (WindowPtr) LookupIDByType (id, RT_WINDOW); - if (pWin) - { - winWindowPriv(pWin); - if (pWinPriv->hWnd) { - hIcon = winOverrideIcon ((unsigned long)pWin); - if (!hIcon) { - hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON)); - if (!hIcon) { - hIcon = g_hIconX; - hIconSmall = g_hSmallIconX; - } else { - /* Leave undefined if not found */ - hIconSmall = winXIconToHICON (pWin, GetSystemMetrics(SM_CXSMICON)); - } - } - - /* Set the large icon */ - hIconOld = (HICON) SendMessage (pWinPriv->hWnd, - WM_SETICON, ICON_BIG, (LPARAM) hIcon); - - /* Delete the icon if its not the default */ - winDestroyIcon(hIconOld); - - /* Same for the small icon */ - hIconOld = (HICON) SendMessage (pWinPriv->hWnd, - WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall); - winDestroyIcon(hIconOld); - } - } -} - -void winInitGlobalIcons (void) -{ - int sm_cx = GetSystemMetrics(SM_CXICON); - int sm_cxsm = GetSystemMetrics(SM_CXSMICON); - /* Load default X icon in case it's not ready yet */ - if (!g_hIconX) - { - g_hIconX = winOverrideDefaultIcon(sm_cx); - g_hSmallIconX = winOverrideDefaultIcon(sm_cxsm); - } - - if (!g_hIconX) - { - g_hIconX = (HICON)LoadImage (g_hInstance, - MAKEINTRESOURCE(IDI_XWIN), - IMAGE_ICON, - GetSystemMetrics(SM_CXICON), - GetSystemMetrics(SM_CYICON), - 0); - g_hSmallIconX = (HICON)LoadImage (g_hInstance, - MAKEINTRESOURCE(IDI_XWIN), - IMAGE_ICON, - GetSystemMetrics(SM_CXSMICON), - GetSystemMetrics(SM_CYSMICON), - LR_DEFAULTSIZE); - } -} - -void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon) -{ - HICON hIcon, hSmallIcon; - - winInitGlobalIcons(); - - /* Try and get the icon from WM_HINTS */ - hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON)); - hSmallIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXSMICON)); - - /* If we got the small, but not the large one swap them */ - if (!hIcon && hSmallIcon) - { - hIcon = hSmallIcon; - hSmallIcon = NULL; - } - - /* Use default X icon if no icon loaded from WM_HINTS */ - if (!hIcon) { - hIcon = g_hIconX; - hSmallIcon = g_hSmallIconX; - } - - if (pIcon) - *pIcon = hIcon; - else - winDestroyIcon(hIcon); - if (pSmallIcon) - *pSmallIcon = hSmallIcon; - else - winDestroyIcon(hSmallIcon); -} - -void winDestroyIcon(HICON hIcon) -{ - /* Delete the icon if its not the default */ - if (hIcon && - hIcon != g_hIconX && - hIcon != g_hSmallIconX && - !winIconIsOverride((unsigned long)hIcon)) - DestroyIcon (hIcon); -} -#endif +/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Earle F. Philhower, III
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#include "dixevents.h"
+#include "winmultiwindowclass.h"
+#include "winprefs.h"
+
+#include "propertyst.h"
+
+#include "propertyst.h"
+#include "windowstr.h"
+
+/*
+ * External global variables
+ */
+
+extern HICON g_hIconX;
+extern HICON g_hSmallIconX;
+
+
+/*
+ * Prototypes for local functions
+ */
+
+static void
+winScaleXBitmapToWindows (int iconSize, int effBPP,
+ PixmapPtr pixmap, unsigned char *image);
+
+
+/*
+ * Scale an X icon bitmap into a Windoze icon bitmap
+ */
+
+static void
+winScaleXBitmapToWindows (int iconSize,
+ int effBPP,
+ PixmapPtr pixmap,
+ unsigned char *image)
+{
+ int row, column, effXBPP, effXDepth;
+ unsigned char *outPtr;
+ char *iconData = 0;
+ int stride, xStride;
+ float factX, factY;
+ int posX, posY;
+ unsigned char *ptr;
+ unsigned int zero;
+ unsigned int color;
+
+ effXBPP = BitsPerPixel(pixmap->drawable.depth);
+ effXDepth = pixmap->drawable.depth;
+
+ if (pixmap->drawable.bitsPerPixel == 15)
+ effXBPP = 16;
+
+ if (pixmap->drawable.depth == 15)
+ effXDepth = 16;
+
+ /* Need 16-bit aligned rows for DDBitmaps */
+ stride = ((iconSize * effBPP + 15) & (~15)) / 8;
+ xStride = PixmapBytePad (pixmap->drawable.width, pixmap->drawable.depth);
+ if (stride == 0 || xStride == 0)
+ {
+ ErrorF ("winScaleXBitmapToWindows - stride or xStride is zero. "
+ "Bailing.\n");
+ return;
+ }
+
+ /* Allocate memory for icon data */
+ iconData = malloc (xStride * pixmap->drawable.height);
+ if (!iconData)
+ {
+ ErrorF ("winScaleXBitmapToWindows - malloc failed for iconData. "
+ "Bailing.\n");
+ return;
+ }
+
+ /* Get icon data */
+ miGetImage ((DrawablePtr) &(pixmap->drawable), 0, 0,
+ pixmap->drawable.width, pixmap->drawable.height,
+ ZPixmap, 0xffffffff, iconData);
+
+ /* Keep aspect ratio */
+ factX = ((float)pixmap->drawable.width) / ((float)iconSize);
+ factY = ((float)pixmap->drawable.height) / ((float)iconSize);
+ if (factX > factY)
+ factY = factX;
+ else
+ factX = factY;
+
+ /* Out-of-bounds, fill icon with zero */
+ zero = 0;
+
+ for (row = 0; row < iconSize; row++)
+ {
+ outPtr = image + stride * row;
+ for (column = 0; column < iconSize; column++)
+ {
+ posX = factX * column;
+ posY = factY * row;
+
+ ptr = (unsigned char*) iconData + posY*xStride;
+ if (effXBPP == 1)
+ {
+ ptr += posX / 8;
+
+ /* Out of X icon bounds, leave space blank */
+ if (posX >= pixmap->drawable.width
+ || posY >= pixmap->drawable.height)
+ ptr = (unsigned char *) &zero;
+
+ if ((*ptr) & (1 << (posX & 7)))
+ switch (effBPP)
+ {
+ case 32:
+ *(outPtr++) = 0;
+ case 24:
+ *(outPtr++) = 0;
+ case 16:
+ *(outPtr++) = 0;
+ case 8:
+ *(outPtr++) = 0;
+ break;
+ case 1:
+ outPtr[column / 8] &= ~(1 << (7 - (column & 7)));
+ break;
+ }
+ else
+ switch (effBPP)
+ {
+ case 32:
+ *(outPtr++) = 255;
+ *(outPtr++) = 255;
+ *(outPtr++) = 255;
+ *(outPtr++) = 0;
+ break;
+ case 24:
+ *(outPtr++) = 255;
+ case 16:
+ *(outPtr++) = 255;
+ case 8:
+ *(outPtr++) = 255;
+ break;
+ case 1:
+ outPtr[column / 8] |= (1 << (7 - (column & 7)));
+ break;
+ }
+ }
+ else if (effXDepth == 24 || effXDepth == 32)
+ {
+ ptr += posX * (effXBPP / 8);
+
+ /* Out of X icon bounds, leave space blank */
+ if (posX >= pixmap->drawable.width
+ || posY >= pixmap->drawable.height)
+ ptr = (unsigned char *) &zero;
+ color = (((*ptr) << 16)
+ + ((*(ptr + 1)) << 8)
+ + ((*(ptr + 2)) << 0));
+ switch (effBPP)
+ {
+ case 32:
+ *(outPtr++) = *(ptr++); /* b */
+ *(outPtr++) = *(ptr++); /* g */
+ *(outPtr++) = *(ptr++); /* r */
+ *(outPtr++) = (effXDepth == 32) ? *(ptr++) : 0x0; /* alpha */
+ break;
+ case 24:
+ *(outPtr++) = *(ptr++);
+ *(outPtr++) = *(ptr++);
+ *(outPtr++) = *(ptr++);
+ break;
+ case 16:
+ color = ((((*ptr) >> 2) << 10)
+ + (((*(ptr + 1)) >> 2) << 5)
+ + (((*(ptr + 2)) >> 2)));
+ *(outPtr++) = (color >> 8);
+ *(outPtr++) = (color & 255);
+ break;
+ case 8:
+ color = (((*ptr))) + (((*(ptr + 1)))) + (((*(ptr + 2))));
+ color /= 3;
+ *(outPtr++) = color;
+ break;
+ case 1:
+ if (color)
+ outPtr[column / 8] |= (1 << (7 - (column & 7)));
+ else
+ outPtr[column / 8] &= ~(1 << (7 - (column & 7)));
+ }
+ }
+ else if (effXDepth == 16)
+ {
+ ptr += posX * (effXBPP / 8);
+
+ /* Out of X icon bounds, leave space blank */
+ if (posX >= pixmap->drawable.width
+ || posY >= pixmap->drawable.height)
+ ptr = (unsigned char *) &zero;
+ color = ((*ptr) << 8) + (*(ptr + 1));
+ switch (effBPP)
+ {
+ case 32:
+ *(outPtr++) = (color & 31) << 2;
+ *(outPtr++) = ((color >> 5) & 31) << 2;
+ *(outPtr++) = ((color >> 10) & 31) << 2;
+ *(outPtr++) = 0; /* resvd */
+ break;
+ case 24:
+ *(outPtr++) = (color & 31) << 2;
+ *(outPtr++) = ((color >> 5) & 31) << 2;
+ *(outPtr++) = ((color >> 10) & 31) << 2;
+ break;
+ case 16:
+ *(outPtr++) = *(ptr++);
+ *(outPtr++) = *(ptr++);
+ break;
+ case 8:
+ *(outPtr++) = (((color & 31)
+ + ((color >> 5) & 31)
+ + ((color >> 10) & 31)) / 3) << 2;
+ break;
+ case 1:
+ if (color)
+ outPtr[column / 8] |= (1 << (7 - (column & 7)));
+ else
+ outPtr[column / 8] &= ~(1 << (7 - (column & 7)));
+ break;
+ } /* end switch(effbpp) */
+ } /* end if effxbpp==16) */
+ } /* end for column */
+ } /* end for row */
+ free (iconData);
+}
+
+static HICON
+NetWMToWinIconAlpha(uint32_t *icon)
+{
+ int width = icon[0];
+ int height = icon[1];
+ uint32_t *pixels = &icon[2];
+ HICON result;
+ HDC hdc = GetDC(NULL);
+ uint32_t *DIB_pixels;
+ ICONINFO ii = {TRUE};
+ BITMAPV4HEADER bmh = {sizeof(bmh)};
+
+ /* Define an ARGB pixel format used for Color+Alpha icons */
+ bmh.bV4Width = width;
+ bmh.bV4Height = -height; /* Invert the image */
+ bmh.bV4Planes = 1;
+ bmh.bV4BitCount = 32;
+ bmh.bV4V4Compression = BI_BITFIELDS;
+ bmh.bV4AlphaMask = 0xFF000000;
+ bmh.bV4RedMask = 0x00FF0000;
+ bmh.bV4GreenMask = 0x0000FF00;
+ bmh.bV4BlueMask = 0x000000FF;
+
+ ii.hbmColor = CreateDIBSection(hdc, (BITMAPINFO*)&bmh,
+ DIB_RGB_COLORS, (void**)&DIB_pixels, NULL, 0);
+ ReleaseDC(NULL, hdc);
+ ii.hbmMask = CreateBitmap(width, height, 1, 1, NULL);
+ memcpy(DIB_pixels, pixels, height*width*4);
+
+ /* CreateIconIndirect() traditionally required DDBitmaps */
+ /* Systems from WinXP accept 32-bit ARGB DIBitmaps with full 8-bit alpha support */
+ /* The icon is created with a DIB + empty DDB mask (an MS example does the same) */
+ result = CreateIconIndirect(&ii);
+
+ DeleteObject(ii.hbmColor);
+ DeleteObject(ii.hbmMask);
+
+ winDebug("NetWMToWinIconAlpha - %d x %d = %p\n", icon[0], icon[1], result);
+ return result;
+}
+
+static HICON
+NetWMToWinIconThreshold(uint32_t *icon)
+{
+ int width = icon[0];
+ int height = icon[1];
+ uint32_t *pixels = &icon[2];
+ int row, col;
+ HICON result;
+ ICONINFO ii = {TRUE};
+
+ HDC hdc = GetDC(NULL);
+ HDC xorDC = CreateCompatibleDC(hdc);
+ HDC andDC = CreateCompatibleDC(hdc);
+ ii.hbmColor = CreateCompatibleBitmap(hdc, width, height);
+ ii.hbmMask = CreateCompatibleBitmap(hdc, width, height);
+ ReleaseDC(NULL, hdc);
+ SelectObject(xorDC, ii.hbmColor);
+ SelectObject(andDC, ii.hbmMask);
+
+ for (row = 0; row < height; row++) {
+ for (col = 0; col < width; col++) {
+ if ((*pixels & 0xFF000000) > 31<<24) { /* 31 alpha threshold, i.e. opaque above, transparent below */
+ SetPixelV(xorDC, col, row, RGB(((char*)pixels)[2], ((char*)pixels)[1],
+ ((char*)pixels)[0]));
+ SetPixelV(andDC, col, row, RGB(0, 0, 0)); /* black mask */
+ }
+ else {
+ SetPixelV(xorDC, col, row, RGB(0, 0, 0));
+ SetPixelV(andDC, col, row, RGB(255, 255, 255)); /* white mask */
+ }
+ pixels++;
+ }
+ }
+ DeleteDC(xorDC);
+ DeleteDC(andDC);
+
+ result = CreateIconIndirect(&ii);
+
+ DeleteObject(ii.hbmColor);
+ DeleteObject(ii.hbmMask );
+
+ winDebug("NetWMToWinIconThreshold - %d x %d = %p\n", icon[0], icon[1], result);
+ return result;
+}
+
+static HICON
+NetWMToWinIcon(int bpp, uint32_t *icon)
+{
+ static Bool hasIconAlphaChannel = FALSE;
+ static BOOL versionChecked = FALSE;
+
+ if (!versionChecked)
+ {
+ OSVERSIONINFOEX osvi = {0};
+ ULONGLONG dwlConditionMask = 0;
+
+ osvi.dwOSVersionInfoSize = sizeof (osvi);
+ osvi.dwMajorVersion = 5;
+ osvi.dwMinorVersion = 1;
+
+ /* Windows versions later than XP have icon alpha channel suport, 2000 does not */
+ VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
+ VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
+ hasIconAlphaChannel = VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask);
+ versionChecked = TRUE;
+
+ winDebug("OS has icon alpha channel support: %s\n", hasIconAlphaChannel ? "yes" : "no");
+ }
+
+ if (hasIconAlphaChannel && (bpp==32))
+ return NetWMToWinIconAlpha(icon);
+ else
+ return NetWMToWinIconThreshold(icon);
+}
+
+static pointer
+GetWindowProp(WindowPtr pWin, Atom name, long int *size_return)
+{
+ struct _Window *pwin;
+ struct _Property *prop;
+
+ if (!pWin || !name) {
+ ErrorF ("GetWindowProp - pWin or name was NULL\n");
+ return 0;
+ }
+ pwin = (struct _Window*) pWin;
+ if (!pwin->optional) return NULL;
+ for (prop = (struct _Property *) pwin->optional->userProps;
+ prop;
+ prop=prop->next){
+ if (prop->propertyName == name) {
+ *size_return=prop->size;
+ return prop->data;
+ }
+ }
+ return NULL;
+}
+
+/*
+ * Attempt to create a custom icon from the WM_HINTS bitmaps
+ */
+
+HICON
+winXIconToHICON (WindowPtr pWin, int iconSize)
+{
+ unsigned char *mask, *image, *imageMask;
+ unsigned char *dst, *src;
+ PixmapPtr iconPtr;
+ PixmapPtr maskPtr;
+ int planes, bpp, effBPP, stride, maskStride, i;
+ int biggest_size = 0;
+ HDC hDC;
+ ICONINFO ii;
+ WinXWMHints hints;
+ HICON hIcon = NULL;
+ uint32_t *biggest_icon = NULL;
+
+ /* Try to get _NET_WM_ICON icons first */
+ static Atom _XA_NET_WM_ICON;
+ static int generation;
+ uint32_t *icon, *icon_data = NULL;
+ long int size=0;
+
+ hDC = GetDC (GetDesktopWindow ());
+ planes = GetDeviceCaps (hDC, PLANES);
+ bpp = GetDeviceCaps (hDC, BITSPIXEL);
+ ReleaseDC (GetDesktopWindow (), hDC);
+
+ if (generation != serverGeneration) {
+ generation = serverGeneration;
+ _XA_NET_WM_ICON = MakeAtom("_NET_WM_ICON", 12, TRUE);
+ }
+
+ if (_XA_NET_WM_ICON) icon_data = GetWindowProp(pWin, _XA_NET_WM_ICON, &size);
+ if (icon_data)
+ {
+ for(icon = icon_data;
+ icon < &icon_data[size] && *icon;
+ icon = &icon[icon[0]*icon[1]+2])
+ {
+ if (icon[0]==iconSize && icon[1]==iconSize)
+ return NetWMToWinIcon(bpp, icon);
+ /* Find the biggest icon and let Windows scale the size */
+ else if (biggest_size < icon[0])
+ {
+ biggest_icon = icon;
+ biggest_size = icon[0];
+ }
+ }
+ if (biggest_icon)
+ return NetWMToWinIcon(bpp, biggest_icon);
+ }
+ winDebug("winXIconToHICON - pWin %x: no suitable NetIcon\n",(int)pWin, iconSize);
+
+ winMultiWindowGetWMHints (pWin, &hints);
+ if (!hints.icon_pixmap) return NULL;
+
+ dixLookupResourceByType((pointer) &iconPtr, hints.icon_pixmap, RT_PIXMAP,
+ NullClient, DixUnknownAccess);
+
+ if (!iconPtr) return NULL;
+
+ /* 15 BPP is really 16BPP as far as we care */
+ if (bpp == 15)
+ effBPP = 16;
+ else
+ effBPP = bpp;
+
+ /* Need 16-bit aligned rows for DDBitmaps */
+ stride = ((iconSize * effBPP + 15) & (~15)) / 8;
+
+ /* Mask is 1-bit deep */
+ maskStride = ((iconSize * 1 + 15) & (~15)) / 8;
+
+ image = malloc (stride * iconSize);
+ imageMask = malloc (stride * iconSize);
+ /* Default to a completely black mask */
+ mask = calloc (maskStride, iconSize);
+
+ winScaleXBitmapToWindows (iconSize, effBPP, iconPtr, image);
+ dixLookupResourceByType((pointer) &maskPtr, hints.icon_mask, RT_PIXMAP,
+ NullClient, DixUnknownAccess);
+
+ if (maskPtr)
+ {
+ winScaleXBitmapToWindows (iconSize, 1, maskPtr, mask);
+
+ winScaleXBitmapToWindows (iconSize, effBPP, maskPtr, imageMask);
+
+ /* Now we need to set all bits of the icon which are not masked */
+ /* on to 0 because Color is really an XOR, not an OR function */
+ dst = image;
+ src = imageMask;
+
+ for (i = 0; i < (stride * iconSize); i++)
+ if ((*(src++)))
+ *(dst++) = 0;
+ else
+ dst++;
+ }
+
+ ii.fIcon = TRUE;
+ ii.xHotspot = 0; /* ignored */
+ ii.yHotspot = 0; /* ignored */
+
+ /* Create Win32 mask from pixmap shape */
+ ii.hbmMask = CreateBitmap (iconSize, iconSize, planes, 1, mask);
+
+ /* Create Win32 bitmap from pixmap */
+ ii.hbmColor = CreateBitmap (iconSize, iconSize, planes, bpp, image);
+
+ /* Merge Win32 mask and bitmap into icon */
+ hIcon = CreateIconIndirect (&ii);
+
+ /* Release Win32 mask and bitmap */
+ DeleteObject (ii.hbmMask);
+ DeleteObject (ii.hbmColor);
+
+ /* Free X mask and bitmap */
+ free (mask);
+ free (image);
+ free (imageMask);
+
+ return hIcon;
+}
+
+
+
+/*
+ * Change the Windows window icon
+ */
+
+#ifdef XWIN_MULTIWINDOW
+void
+winUpdateIcon (Window id)
+{
+ WindowPtr pWin;
+ HICON hIcon, hIconSmall=NULL, hIconOld;
+
+ dixLookupResourceByType((pointer) &pWin, id, RT_WINDOW, NullClient, DixUnknownAccess);
+ if (pWin)
+ {
+ winWindowPriv(pWin);
+ if (pWinPriv->hWnd) {
+ hIcon = winOverrideIcon ((unsigned long)pWin);
+ if (!hIcon) {
+ hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON));
+ if (!hIcon) {
+ hIcon = g_hIconX;
+ hIconSmall = g_hSmallIconX;
+ } else {
+ /* Leave undefined if not found */
+ hIconSmall = winXIconToHICON (pWin, GetSystemMetrics(SM_CXSMICON));
+ }
+ }
+
+ /* Set the large icon */
+ hIconOld = (HICON) SendMessage (pWinPriv->hWnd,
+ WM_SETICON, ICON_BIG, (LPARAM) hIcon);
+
+ /* Delete the icon if its not the default */
+ winDestroyIcon(hIconOld);
+
+ /* Same for the small icon */
+ hIconOld = (HICON) SendMessage (pWinPriv->hWnd,
+ WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall);
+ winDestroyIcon(hIconOld);
+ }
+ }
+}
+
+void winInitGlobalIcons (void)
+{
+ int sm_cx = GetSystemMetrics(SM_CXICON);
+ int sm_cxsm = GetSystemMetrics(SM_CXSMICON);
+ /* Load default X icon in case it's not ready yet */
+ if (!g_hIconX)
+ {
+ g_hIconX = winOverrideDefaultIcon(sm_cx);
+ g_hSmallIconX = winOverrideDefaultIcon(sm_cxsm);
+ }
+
+ if (!g_hIconX)
+ {
+ g_hIconX = (HICON)LoadImage (g_hInstance,
+ MAKEINTRESOURCE(IDI_XWIN),
+ IMAGE_ICON,
+ GetSystemMetrics(SM_CXICON),
+ GetSystemMetrics(SM_CYICON),
+ 0);
+ g_hSmallIconX = (HICON)LoadImage (g_hInstance,
+ MAKEINTRESOURCE(IDI_XWIN),
+ IMAGE_ICON,
+ GetSystemMetrics(SM_CXSMICON),
+ GetSystemMetrics(SM_CYSMICON),
+ LR_DEFAULTSIZE);
+ }
+}
+
+void winSelectIcons(WindowPtr pWin, HICON *pIcon, HICON *pSmallIcon)
+{
+ HICON hIcon, hSmallIcon;
+
+ winInitGlobalIcons();
+
+ /* Try and get the icon from WM_HINTS */
+ hIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXICON));
+ hSmallIcon = winXIconToHICON (pWin, GetSystemMetrics(SM_CXSMICON));
+
+ /* If we got the small, but not the large one swap them */
+ if (!hIcon && hSmallIcon)
+ {
+ hIcon = hSmallIcon;
+ hSmallIcon = NULL;
+ }
+
+ /* Use default X icon if no icon loaded from WM_HINTS */
+ if (!hIcon) {
+ hIcon = g_hIconX;
+ hSmallIcon = g_hSmallIconX;
+ }
+
+ if (pIcon)
+ *pIcon = hIcon;
+ else
+ winDestroyIcon(hIcon);
+ if (pSmallIcon)
+ *pSmallIcon = hSmallIcon;
+ else
+ winDestroyIcon(hSmallIcon);
+}
+
+void winDestroyIcon(HICON hIcon)
+{
+ /* Delete the icon if its not the default */
+ if (hIcon &&
+ hIcon != g_hIconX &&
+ hIcon != g_hSmallIconX &&
+ !winIconIsOverride((unsigned long)hIcon))
+ DestroyIcon (hIcon);
+}
+#endif
diff --git a/xorg-server/hw/xwin/winmultiwindowwindow.c b/xorg-server/hw/xwin/winmultiwindowwindow.c index 38f39bd7d..26f8a2e41 100644 --- a/xorg-server/hw/xwin/winmultiwindowwindow.c +++ b/xorg-server/hw/xwin/winmultiwindowwindow.c @@ -1,902 +1,891 @@ -/* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - *Copyright (C) Colin Harrison 2005-2008 - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of the XFree86 Project - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from the XFree86 Project. - * - * Authors: Kensuke Matsuzaki - * Earle F. Philhower, III - * Harold L Hunt II - * Colin Harrison - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" -#include "dixevents.h" -#include "winmultiwindowclass.h" -#include "winprefs.h" - -/* - * External global variables - */ - -extern HICON g_hIconX; -extern HICON g_hSmallIconX; -extern HWND g_hDlgDepthChange; - -/* - * Prototypes for local functions - */ - -void -winCreateWindowsWindow (WindowPtr pWin); - -static void -winDestroyWindowsWindow (WindowPtr pWin); - -static void -winUpdateWindowsWindow (WindowPtr pWin); - -static void -winFindWindow (pointer value, XID id, pointer cdata); - -/* - * Macros - */ - -#define SubSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & SubstructureNotifyMask) - -#define StrSend(pWin) \ - ((pWin->eventMask|wOtherEventMasks(pWin)) & StructureNotifyMask) - -#define SubStrSend(pWin,pParent) (StrSend(pWin) || SubSend(pParent)) - -static -void winInitMultiWindowClass(void) -{ - static wATOM atomXWinClass=0; - WNDCLASSEX wcx; - - if (atomXWinClass==0) - { - /* Setup our window class */ - wcx.cbSize=sizeof(WNDCLASSEX); - wcx.style = CS_HREDRAW | CS_VREDRAW; - wcx.lpfnWndProc = winTopLevelWindowProc; - wcx.cbClsExtra = 0; - wcx.cbWndExtra = 0; - wcx.hInstance = g_hInstance; - wcx.hIcon = g_hIconX; - wcx.hCursor = 0; - wcx.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); - wcx.lpszMenuName = NULL; - wcx.lpszClassName = WINDOW_CLASS_X; - wcx.hIconSm = g_hSmallIconX; - -#if CYGMULTIWINDOW_DEBUG - winDebug ("winCreateWindowsWindow - Creating class: %s\n", WINDOW_CLASS_X); -#endif - - atomXWinClass = RegisterClassEx (&wcx); - } -} - -/* - * CreateWindow - See Porting Layer Definition - p. 37 - */ - -Bool -winCreateWindowMultiWindow (WindowPtr pWin) -{ - Bool fResult = TRUE; - ScreenPtr pScreen = pWin->drawable.pScreen; - winWindowPriv(pWin); - winScreenPriv(pScreen); - -#if CYGMULTIWINDOW_DEBUG - winDebug ("winCreateWindowMultiWindow - pWin: %p\n", pWin); -#endif - - WIN_UNWRAP(CreateWindow); - fResult = (*pScreen->CreateWindow) (pWin); - WIN_WRAP(CreateWindow, winCreateWindowMultiWindow); - - /* Initialize some privates values */ - pWinPriv->hRgn = NULL; - pWinPriv->hWnd = NULL; - pWinPriv->pScreenPriv = winGetScreenPriv(pWin->drawable.pScreen); - pWinPriv->fXKilled = FALSE; - - return fResult; -} - - -/* - * DestroyWindow - See Porting Layer Definition - p. 37 - */ - -Bool -winDestroyWindowMultiWindow (WindowPtr pWin) -{ - Bool fResult = TRUE; - ScreenPtr pScreen = pWin->drawable.pScreen; - winWindowPriv(pWin); - winScreenPriv(pScreen); - -#if CYGMULTIWINDOW_DEBUG - winDebug ("winDestroyWindowMultiWindow - pWin: %p\n", pWin); -#endif - - WIN_UNWRAP(DestroyWindow); - fResult = (*pScreen->DestroyWindow)(pWin); - WIN_WRAP(DestroyWindow, winDestroyWindowMultiWindow); - - /* Flag that the window has been destroyed */ - pWinPriv->fXKilled = TRUE; - - /* Kill the MS Windows window associated with this window */ - winDestroyWindowsWindow (pWin); - - return fResult; -} - - -/* - * PositionWindow - See Porting Layer Definition - p. 37 - * - * This function adjusts the position and size of Windows window - * with respect to the underlying X window. This is the inverse - * of winAdjustXWindow, which adjusts X window to Windows window. - */ - -Bool -winPositionWindowMultiWindow (WindowPtr pWin, int x, int y) -{ - Bool fResult = TRUE; - int iX, iY, iWidth, iHeight; - ScreenPtr pScreen = pWin->drawable.pScreen; - winWindowPriv(pWin); - winScreenPriv(pScreen); - - HWND hWnd = pWinPriv->hWnd; - RECT rcNew; - RECT rcOld; -#ifdef WINDBG - RECT rcClient; - RECT *lpRc; -#endif - DWORD dwExStyle; - DWORD dwStyle; - - winDebug ("winPositionWindowMultiWindow - pWin: %p\n", pWin); - - WIN_UNWRAP(PositionWindow); - fResult = (*pScreen->PositionWindow)(pWin, x, y); - WIN_WRAP(PositionWindow, winPositionWindowMultiWindow); - - winDebug ("winPositionWindowMultiWindow: (x, y) = (%d, %d)\n", - x, y); - - /* Bail out if the Windows window handle is bad */ - if (!hWnd) - { - winDebug ("\timmediately return since hWnd is NULL\n"); - return fResult; - } - - /* Get the Windows window style and extended style */ - dwExStyle = GetWindowLongPtr (hWnd, GWL_EXSTYLE); - dwStyle = GetWindowLongPtr (hWnd, GWL_STYLE); - - /* Get the X and Y location of the X window */ - 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; - iHeight = pWin->drawable.height; - - /* Store the origin, height, and width in a rectangle structure */ - SetRect (&rcNew, iX, iY, iX + iWidth, iY + iHeight); - -#if CYGMULTIWINDOW_DEBUG - lpRc = &rcNew; - winDebug ("winPositionWindowMultiWindow - (%d ms)drawable (%d, %d)-(%d, %d)\n", - GetTickCount (), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom); -#endif - - /* - * Calculate the required size of the Windows window rectangle, - * given the size of the Windows window client area. - */ - AdjustWindowRectEx (&rcNew, dwStyle, FALSE, dwExStyle); - - /* Get a rectangle describing the old Windows window */ - GetWindowRect (hWnd, &rcOld); - -#if CYGMULTIWINDOW_DEBUG - /* Get a rectangle describing the Windows window client area */ - GetClientRect (hWnd, &rcClient); - - lpRc = &rcNew; - winDebug ("winPositionWindowMultiWindow - (%d ms)rcNew (%d, %d)-(%d, %d)\n", - GetTickCount (), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom); - - lpRc = &rcOld; - winDebug ("winPositionWindowMultiWindow - (%d ms)rcOld (%d, %d)-(%d, %d)\n", - GetTickCount (), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom); - - lpRc = &rcClient; - winDebug ("(%d ms)rcClient (%d, %d)-(%d, %d)\n", - GetTickCount (), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom); -#endif - - /* Check if the old rectangle and new rectangle are the same */ - if (!EqualRect (&rcNew, &rcOld)) - { - winDebug ("winPositionWindowMultiWindow - Need to move\n"); - winDebug ("\tMoveWindow to (%ld, %ld) - %ldx%ld\n", rcNew.left, rcNew.top, - rcNew.right - rcNew.left, rcNew.bottom - rcNew.top); - - /* Change the position and dimensions of the Windows window */ - MoveWindow (hWnd, - rcNew.left, rcNew.top, - rcNew.right - rcNew.left, rcNew.bottom - rcNew.top, - TRUE); - } - else - { - winDebug ("winPositionWindowMultiWindow - Not need to move\n"); - } - - return fResult; -} - - -/* - * ChangeWindowAttributes - See Porting Layer Definition - p. 37 - */ - -Bool -winChangeWindowAttributesMultiWindow (WindowPtr pWin, unsigned long mask) -{ - Bool fResult = TRUE; - ScreenPtr pScreen = pWin->drawable.pScreen; - winScreenPriv(pScreen); - - winDebug ("winChangeWindowAttributesMultiWindow - pWin: %08x\n", pWin); - - WIN_UNWRAP(ChangeWindowAttributes); - fResult = (*pScreen->ChangeWindowAttributes)(pWin, mask); - WIN_WRAP(ChangeWindowAttributes, winChangeWindowAttributesMultiWindow); - - /* - * NOTE: We do not currently need to do anything here. - */ - - return fResult; -} - - -/* - * UnmapWindow - See Porting Layer Definition - p. 37 - * Also referred to as UnrealizeWindow - */ - -Bool -winUnmapWindowMultiWindow (WindowPtr pWin) -{ - Bool fResult = TRUE; - ScreenPtr pScreen = pWin->drawable.pScreen; - winWindowPriv(pWin); - winScreenPriv(pScreen); - -#if CYGMULTIWINDOW_DEBUG - winDebug ("winUnmapWindowMultiWindow - pWin: %08x\n", pWin); -#endif - - WIN_UNWRAP(UnrealizeWindow); - fResult = (*pScreen->UnrealizeWindow)(pWin); - WIN_WRAP(UnrealizeWindow, winUnmapWindowMultiWindow); - - /* Flag that the window has been killed */ - pWinPriv->fXKilled = TRUE; - - /* Destroy the Windows window associated with this X window */ - winDestroyWindowsWindow (pWin); - - return fResult; -} - - -/* - * MapWindow - See Porting Layer Definition - p. 37 - * Also referred to as RealizeWindow - */ - -Bool -winMapWindowMultiWindow (WindowPtr pWin) -{ - Bool fResult = TRUE; - ScreenPtr pScreen = pWin->drawable.pScreen; - winWindowPriv(pWin); - winScreenPriv(pScreen); - -#if CYGMULTIWINDOW_DEBUG - winDebug ("winMapWindowMultiWindow - pWin: %08x\n", pWin); -#endif - - WIN_UNWRAP(RealizeWindow); - fResult = (*pScreen->RealizeWindow)(pWin); - WIN_WRAP(RealizeWindow, winMapWindowMultiWindow); - - /* Flag that this window has not been destroyed */ - pWinPriv->fXKilled = FALSE; - - /* Refresh/redisplay the Windows window associated with this X window */ - winUpdateWindowsWindow (pWin); - - /* Update the Windows window's shape */ - winReshapeMultiWindow (pWin); - winUpdateRgnMultiWindow (pWin); - - return fResult; -} - - -/* - * ReparentWindow - See Porting Layer Definition - p. 42 - */ - -void -winReparentWindowMultiWindow (WindowPtr pWin, WindowPtr pPriorParent) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - winScreenPriv(pScreen); - -#if CYGMULTIWINDOW_DEBUG - winDebug ("winReparentMultiWindow - pWin: %08x\n", pWin); -#endif - - WIN_UNWRAP(ReparentWindow); - if (pScreen->ReparentWindow) - (*pScreen->ReparentWindow)(pWin, pPriorParent); - WIN_WRAP(ReparentWindow, winReparentWindowMultiWindow); - - /* Update the Windows window associated with this X window */ - winUpdateWindowsWindow (pWin); -} - - -/* - * RestackWindow - Shuffle the z-order of a window - */ - -void -winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - winScreenPriv(pScreen); - - winDebug ("winRestackMultiWindow - %08x\n", pWin); - - WIN_UNWRAP(RestackWindow); - if (pScreen->RestackWindow) - (*pScreen->RestackWindow)(pWin, pOldNextSib); - WIN_WRAP(RestackWindow, winRestackWindowMultiWindow); - - /* - * Calling winReorderWindowsMultiWindow here means our window manager - * (i.e. Windows Explorer) has initiative to determine Z order. - */ - if (pWin->nextSib != pOldNextSib) - winReorderWindowsMultiWindow (); -} - - -/* - * winCreateWindowsWindow - Create a Windows window associated with an X window - */ - -void -winCreateWindowsWindow (WindowPtr pWin) -{ - int iX, iY; - int iWidth; - int iHeight; - HWND hWnd; - HWND hFore = NULL; - winWindowPriv(pWin); - HICON hIcon; - HICON hIconSmall; - winPrivScreenPtr pScreenPriv = pWinPriv->pScreenPriv; - WinXSizeHints hints; - WindowPtr pDaddy; - - winInitMultiWindowClass(); - - winDebug ("winCreateWindowsWindow - pWin: %08x\n", pWin); - - iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN); - iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN); - - /* Default positions if none specified */ - if (!winMultiWindowGetWMNormalHints(pWin, &hints)) - hints.flags = 0; - if ( !(hints.flags & (USPosition|PPosition)) && - !winMultiWindowGetTransientFor (pWin, NULL) && - !pWin->overrideRedirect ) - { - iX = CW_USEDEFAULT; - iY = CW_USEDEFAULT; - } - - iWidth = pWin->drawable.width; - iHeight = pWin->drawable.height; - - if (winMultiWindowGetTransientFor (pWin, &pDaddy)) - { - if (pDaddy) - { - hFore = GetForegroundWindow(); - if (hFore && (pDaddy != (WindowPtr)GetProp(hFore, WIN_WID_PROP))) hFore = NULL; - } - } - - /* Create the window */ - /* Make it OVERLAPPED in create call since WS_POPUP doesn't support */ - /* CW_USEDEFAULT, change back to popup after creation */ - hWnd = CreateWindowExA (WS_EX_TOOLWINDOW, /* Extended styles */ - WINDOW_CLASS_X, /* Class name */ - WINDOW_TITLE_X, /* Window name */ - WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, - iX, /* Horizontal position */ - iY, /* Vertical position */ - iWidth, /* Right edge */ - iHeight, /* Bottom edge */ - hFore, /* Null or Parent window if transient*/ - (HMENU) NULL, /* No menu */ - GetModuleHandle (NULL), /* Instance handle */ - pWin); /* ScreenPrivates */ - if (hWnd == NULL) - { - ErrorF ("winCreateWindowsWindow - CreateWindowExA () failed: %d\n", - (int) GetLastError ()); - } - pWinPriv->hWnd = hWnd; - - /* Set application or .XWinrc defined Icons */ - winSelectIcons(pWin, &hIcon, &hIconSmall); - if (hIcon) SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) hIcon); - if (hIconSmall) SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall); - - /* Change style back to popup, already placed... */ - SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); - SetWindowPos (hWnd, 0, 0, 0, 0, 0, - SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); - /* Make sure it gets the proper system menu for a WS_POPUP, too */ - GetSystemMenu (hWnd, TRUE); - - /* Cause any .XWinrc menus to be added in main WNDPROC */ - PostMessage (hWnd, WM_INIT_SYS_MENU, 0, 0); - - SetProp (hWnd, WIN_WID_PROP, (HANDLE) winGetWindowID(pWin)); - - /* Flag that this Windows window handles its own activation */ - SetProp (hWnd, WIN_NEEDMANAGE_PROP, (HANDLE) 0); - - /* Call engine-specific create window procedure */ - (*pScreenPriv->pwinFinishCreateWindowsWindow) (pWin); -} - - -Bool winInDestroyWindowsWindow = FALSE; -/* - * winDestroyWindowsWindow - Destroy a Windows window associated - * with an X window - */ -static void -winDestroyWindowsWindow (WindowPtr pWin) -{ - MSG msg; - winWindowPriv(pWin); - BOOL oldstate = winInDestroyWindowsWindow; - -#if CYGMULTIWINDOW_DEBUG - winDebug ("winDestroyWindowsWindow\n"); -#endif - - /* Bail out if the Windows window handle is invalid */ - if (pWinPriv->hWnd == NULL) - return; - - winInDestroyWindowsWindow = TRUE; - - SetProp (pWinPriv->hWnd, WIN_WINDOW_PROP, NULL); - /* 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 */ - while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) - { - if (g_hDlgDepthChange == 0 || !IsDialogMessage (g_hDlgDepthChange, &msg)) - { - DispatchMessage (&msg); - } - } - - winInDestroyWindowsWindow = oldstate; - -#if CYGMULTIWINDOW_DEBUG - winDebug ("-winDestroyWindowsWindow\n"); -#endif -} - - -/* - * winUpdateWindowsWindow - Redisplay/redraw a Windows window - * associated with an X window - */ - -static void -winUpdateWindowsWindow (WindowPtr pWin) -{ - winWindowPriv(pWin); - HWND hWnd = pWinPriv->hWnd; - -#if CYGMULTIWINDOW_DEBUG - winDebug ("winUpdateWindowsWindow\n"); -#endif - - /* Check if the Windows window's parents have been destroyed */ - if (pWin->parent != NULL - && pWin->parent->parent == NULL - && pWin->mapped) - { - /* Create the Windows window if it has been destroyed */ - if (hWnd == NULL) - { - winCreateWindowsWindow (pWin); - assert (pWinPriv->hWnd != NULL); - } - - /* Display the window without activating it */ - ShowWindow (pWinPriv->hWnd, SW_SHOWNOACTIVATE); - - /* Send first paint message */ - UpdateWindow (pWinPriv->hWnd); - } - else if (hWnd != NULL) - { - /* Destroy the Windows window if its parents are destroyed */ - winDestroyWindowsWindow (pWin); - assert (pWinPriv->hWnd == NULL); - } - -#if CYGMULTIWINDOW_DEBUG - winDebug ("-winUpdateWindowsWindow\n"); -#endif -} - - -/* - * winGetWindowID - - */ - -XID -winGetWindowID (WindowPtr pWin) -{ - WindowIDPairRec wi = {pWin, 0}; - ClientPtr c = wClient(pWin); - - /* */ - FindClientResourcesByType (c, RT_WINDOW, winFindWindow, &wi); - -#if CYGMULTIWINDOW_DEBUG - winDebug ("winGetWindowID - Window ID: %d\n", wi.id); -#endif - - return wi.id; -} - - -/* - * winFindWindow - - */ - -static void -winFindWindow (pointer value, XID id, pointer cdata) -{ - WindowIDPairPtr wi = (WindowIDPairPtr)cdata; - - if (value == wi->value) - { - wi->id = id; - } -} - - -/* - * winReorderWindowsMultiWindow - - */ - -void -winReorderWindowsMultiWindow (void) -{ - HWND hwnd = NULL; - WindowPtr pWin = NULL; - WindowPtr pWinSib = NULL; - XID vlist[2]; - static Bool fRestacking = FALSE; /* Avoid recusive calls to this function */ - DWORD dwCurrentProcessID = GetCurrentProcessId (); - DWORD dwWindowProcessID = 0; - - winDebug ("winReorderWindowsMultiWindow\n"); - - if (fRestacking) - { - /* It is a recusive call so immediately exit */ - winDebug ("winReorderWindowsMultiWindow - " - "exit because fRestacking == TRUE\n"); - return; - } - fRestacking = TRUE; - - /* Loop through top level Window windows, descending in Z order */ - for ( hwnd = GetTopWindow (NULL); - hwnd; - hwnd = GetNextWindow (hwnd, GW_HWNDNEXT) ) - { - /* Don't take care of other Cygwin/X process's windows */ - GetWindowThreadProcessId (hwnd, &dwWindowProcessID); - - if ( GetProp (hwnd, WIN_WINDOW_PROP) - && (dwWindowProcessID == dwCurrentProcessID) - && !IsIconic (hwnd) ) /* ignore minimized windows */ - { - pWinSib = pWin; - pWin = GetProp (hwnd, WIN_WINDOW_PROP); - - if (!pWinSib) - { /* 1st window - raise to the top */ - vlist[0] = Above; - - ConfigureWindow (pWin, CWStackMode, vlist, wClient(pWin)); - } - else - { /* 2nd or deeper windows - just below the previous one */ - vlist[0] = winGetWindowID (pWinSib); - vlist[1] = Below; - - ConfigureWindow (pWin, CWSibling | CWStackMode, - vlist, wClient(pWin)); - } - } - } - - fRestacking = FALSE; -} - - -/* - * winMinimizeWindow - Minimize in response to WM_CHANGE_STATE - */ - -void -winMinimizeWindow (Window id) -{ - WindowPtr pWin; - winPrivWinPtr pWinPriv; -#ifdef XWIN_MULTIWINDOWEXTWM - win32RootlessWindowPtr pRLWinPriv; -#endif - HWND hWnd; - ScreenPtr pScreen = NULL; - winPrivScreenPtr pScreenPriv = NULL; - winScreenInfo *pScreenInfo = NULL; - - winDebug ("winMinimizeWindow\n"); - - pWin = (WindowPtr) LookupIDByType (id, RT_WINDOW); - if (!pWin) - { - ErrorF("%s: NULL pWin. Leaving\n", __FUNCTION__); - return; - } - - pScreen = pWin->drawable.pScreen; - if (pScreen) pScreenPriv = winGetScreenPriv(pScreen); - if (pScreenPriv) pScreenInfo = pScreenPriv->pScreenInfo; - -#ifdef XWIN_MULTIWINDOWEXTWM - if (pScreenPriv && pScreenInfo->fInternalWM) - { - pRLWinPriv = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, FALSE); - hWnd = pRLWinPriv->hWnd; - } - else -#else - if (pScreenPriv) -#endif - { - pWinPriv = winGetWindowPriv (pWin); - hWnd = pWinPriv->hWnd; - } - - ShowWindow (hWnd, SW_MINIMIZE); -} - - -/* - * CopyWindow - See Porting Layer Definition - p. 39 - */ -void -winCopyWindowMultiWindow (WindowPtr pWin, DDXPointRec oldpt, - RegionPtr oldRegion) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - winScreenPriv(pScreen); - - winDebug ("CopyWindowMultiWindow\n"); - - WIN_UNWRAP(CopyWindow); - (*pScreen->CopyWindow)(pWin, oldpt, oldRegion); - WIN_WRAP(CopyWindow, winCopyWindowMultiWindow); -} - - -/* - * MoveWindow - See Porting Layer Definition - p. 42 - */ -void -winMoveWindowMultiWindow (WindowPtr pWin, int x, int y, - WindowPtr pSib, VTKind kind) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - winScreenPriv(pScreen); - - winDebug ("MoveWindowMultiWindow to (%d, %d)\n", x, y); - - WIN_UNWRAP(MoveWindow); - (*pScreen->MoveWindow)(pWin, x, y, pSib, kind); - WIN_WRAP(MoveWindow, winMoveWindowMultiWindow); -} - - -/* - * ResizeWindow - See Porting Layer Definition - p. 42 - */ -void -winResizeWindowMultiWindow (WindowPtr pWin, int x, int y, unsigned int w, - unsigned int h, WindowPtr pSib) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - winScreenPriv(pScreen); - - winDebug ("ResizeWindowMultiWindow to (%d, %d) - %dx%d\n", x, y, w, h); - - WIN_UNWRAP(ResizeWindow); - (*pScreen->ResizeWindow)(pWin, x, y, w, h, pSib); - WIN_WRAP(ResizeWindow, winResizeWindowMultiWindow); -} - - -/* - * winAdjustXWindow - * - * Move and resize X window with respect to corresponding Windows window. - * This is called from WM_MOVE/WM_SIZE handlers when the user performs - * any windowing operation (move, resize, minimize, maximize, restore). - * - * The functionality is the inverse of winPositionWindowMultiWindow, which - * adjusts Windows window with respect to X window. - */ -int -winAdjustXWindow (WindowPtr pWin, HWND hwnd) -{ - RECT rcDraw; /* Rect made from pWin->drawable to be adjusted */ - RECT rcWin; /* The source: WindowRect from hwnd */ - DrawablePtr pDraw; - XID vlist[4]; - LONG dX, dY, dW, dH, x, y; - DWORD dwStyle, dwExStyle; - -#define WIDTH(rc) (rc.right - rc.left) -#define HEIGHT(rc) (rc.bottom - rc.top) - - winDebug ("winAdjustXWindow\n"); - - if (IsIconic (hwnd)) - { - winDebug ("\timmediately return because the window is iconized\n"); - /* - * If the Windows window is minimized, its WindowRect has - * meaningless values so we don't adjust X window to it. - */ - vlist[0] = 0; - vlist[1] = 0; - return ConfigureWindow (pWin, CWX | CWY, vlist, wClient(pWin)); - } - - pDraw = &pWin->drawable; - - /* Calculate the window rect from the drawable */ - x = pDraw->x + GetSystemMetrics (SM_XVIRTUALSCREEN); - y = pDraw->y + GetSystemMetrics (SM_YVIRTUALSCREEN); - SetRect (&rcDraw, x, y, x + pDraw->width, y + pDraw->height); - winDebug("\tDrawable extend {%d, %d, %d, %d}, {%d, %d}\n", - rcDraw.left, rcDraw.top, rcDraw.right, rcDraw.bottom, - rcDraw.right - rcDraw.left, rcDraw.bottom - rcDraw.top); - dwExStyle = GetWindowLongPtr (hwnd, GWL_EXSTYLE); - dwStyle = GetWindowLongPtr (hwnd, GWL_STYLE); - winDebug("\tWindowStyle: %08x %08x\n", dwStyle, dwExStyle); - AdjustWindowRectEx (&rcDraw, dwStyle, FALSE, dwExStyle); - - /* The source of adjust */ - GetWindowRect (hwnd, &rcWin); - winDebug("\tWindow extend {%d, %d, %d, %d}, {%d, %d}\n", - rcWin.left, rcWin.top, rcWin.right, rcWin.bottom, - rcWin.right - rcWin.left, rcWin.bottom - rcWin.top); - winDebug("\tDraw extend {%d, %d, %d, %d}, {%d, %d}\n", - rcDraw.left, rcDraw.top, rcDraw.right, rcDraw.bottom, - rcDraw.right - rcDraw.left, rcDraw.bottom - rcDraw.top); - - if (EqualRect (&rcDraw, &rcWin)) { - /* Bail if no adjust is needed */ - winDebug ("\treturn because already adjusted\n"); - return 0; - } - - /* Calculate delta values */ - dX = rcWin.left - rcDraw.left; - dY = rcWin.top - rcDraw.top; - dW = WIDTH(rcWin) - WIDTH(rcDraw); - dH = HEIGHT(rcWin) - HEIGHT(rcDraw); - - /* - * Adjust. - * We may only need to move (vlist[0] and [1]), or only resize - * ([2] and [3]) but currently we set all the parameters and leave - * the decision to ConfigureWindow. The reason is code simplicity. - */ - vlist[0] = pDraw->x + dX - wBorderWidth(pWin); - vlist[1] = pDraw->y + dY - wBorderWidth(pWin); - vlist[2] = pDraw->width + dW; - vlist[3] = pDraw->height + dH; - winDebug ("\tConfigureWindow to (%ld, %ld) - %ldx%ld\n", vlist[0], vlist[1], - vlist[2], vlist[3]); - return ConfigureWindow (pWin, CWX | CWY | CWWidth | CWHeight, - vlist, wClient(pWin)); - -#undef WIDTH -#undef HEIGHT -} - +/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *Copyright (C) Colin Harrison 2005-2008
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Kensuke Matsuzaki
+ * Earle F. Philhower, III
+ * Harold L Hunt II
+ * Colin Harrison
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#include "dixevents.h"
+#include "winmultiwindowclass.h"
+#include "winprefs.h"
+
+/*
+ * External global variables
+ */
+
+extern HICON g_hIconX;
+extern HICON g_hSmallIconX;
+extern HWND g_hDlgDepthChange;
+
+/*
+ * Prototypes for local functions
+ */
+
+void
+winCreateWindowsWindow (WindowPtr pWin);
+
+static void
+winDestroyWindowsWindow (WindowPtr pWin);
+
+static void
+winUpdateWindowsWindow (WindowPtr pWin);
+
+static void
+winFindWindow (pointer value, XID id, pointer cdata);
+
+static
+void winInitMultiWindowClass(void)
+{
+ static wATOM atomXWinClass=0;
+ WNDCLASSEX wcx;
+
+ if (atomXWinClass==0)
+ {
+ /* Setup our window class */
+ wcx.cbSize=sizeof(WNDCLASSEX);
+ wcx.style = CS_HREDRAW | CS_VREDRAW;
+ wcx.lpfnWndProc = winTopLevelWindowProc;
+ wcx.cbClsExtra = 0;
+ wcx.cbWndExtra = 0;
+ wcx.hInstance = g_hInstance;
+ wcx.hIcon = g_hIconX;
+ wcx.hCursor = 0;
+ wcx.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
+ wcx.lpszMenuName = NULL;
+ wcx.lpszClassName = WINDOW_CLASS_X;
+ wcx.hIconSm = g_hSmallIconX;
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("winCreateWindowsWindow - Creating class: %s\n", WINDOW_CLASS_X);
+#endif
+
+ atomXWinClass = RegisterClassEx (&wcx);
+ }
+}
+
+/*
+ * CreateWindow - See Porting Layer Definition - p. 37
+ */
+
+Bool
+winCreateWindowMultiWindow (WindowPtr pWin)
+{
+ Bool fResult = TRUE;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winWindowPriv(pWin);
+ winScreenPriv(pScreen);
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("winCreateWindowMultiWindow - pWin: %p\n", pWin);
+#endif
+
+ WIN_UNWRAP(CreateWindow);
+ fResult = (*pScreen->CreateWindow) (pWin);
+ WIN_WRAP(CreateWindow, winCreateWindowMultiWindow);
+
+ /* Initialize some privates values */
+ pWinPriv->hRgn = NULL;
+ pWinPriv->hWnd = NULL;
+ pWinPriv->pScreenPriv = winGetScreenPriv(pWin->drawable.pScreen);
+ pWinPriv->fXKilled = FALSE;
+
+ return fResult;
+}
+
+
+/*
+ * DestroyWindow - See Porting Layer Definition - p. 37
+ */
+
+Bool
+winDestroyWindowMultiWindow (WindowPtr pWin)
+{
+ Bool fResult = TRUE;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winWindowPriv(pWin);
+ winScreenPriv(pScreen);
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("winDestroyWindowMultiWindow - pWin: %p\n", pWin);
+#endif
+
+ WIN_UNWRAP(DestroyWindow);
+ fResult = (*pScreen->DestroyWindow)(pWin);
+ WIN_WRAP(DestroyWindow, winDestroyWindowMultiWindow);
+
+ /* Flag that the window has been destroyed */
+ pWinPriv->fXKilled = TRUE;
+
+ /* Kill the MS Windows window associated with this window */
+ winDestroyWindowsWindow (pWin);
+
+ return fResult;
+}
+
+
+/*
+ * PositionWindow - See Porting Layer Definition - p. 37
+ *
+ * This function adjusts the position and size of Windows window
+ * with respect to the underlying X window. This is the inverse
+ * of winAdjustXWindow, which adjusts X window to Windows window.
+ */
+
+Bool
+winPositionWindowMultiWindow (WindowPtr pWin, int x, int y)
+{
+ Bool fResult = TRUE;
+ int iX, iY, iWidth, iHeight;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winWindowPriv(pWin);
+ winScreenPriv(pScreen);
+
+ HWND hWnd = pWinPriv->hWnd;
+ RECT rcNew;
+ RECT rcOld;
+#ifdef WINDBG
+ RECT rcClient;
+ RECT *lpRc;
+#endif
+ DWORD dwExStyle;
+ DWORD dwStyle;
+
+ winDebug ("winPositionWindowMultiWindow - pWin: %p\n", pWin);
+
+ WIN_UNWRAP(PositionWindow);
+ fResult = (*pScreen->PositionWindow)(pWin, x, y);
+ WIN_WRAP(PositionWindow, winPositionWindowMultiWindow);
+
+ winDebug ("winPositionWindowMultiWindow: (x, y) = (%d, %d)\n",
+ x, y);
+
+ /* Bail out if the Windows window handle is bad */
+ if (!hWnd)
+ {
+ winDebug ("\timmediately return since hWnd is NULL\n");
+ return fResult;
+ }
+
+ /* Get the Windows window style and extended style */
+ dwExStyle = GetWindowLongPtr (hWnd, GWL_EXSTYLE);
+ dwStyle = GetWindowLongPtr (hWnd, GWL_STYLE);
+
+ /* Get the X and Y location of the X window */
+ 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;
+ iHeight = pWin->drawable.height;
+
+ /* Store the origin, height, and width in a rectangle structure */
+ SetRect (&rcNew, iX, iY, iX + iWidth, iY + iHeight);
+
+#if CYGMULTIWINDOW_DEBUG
+ lpRc = &rcNew;
+ winDebug ("winPositionWindowMultiWindow - (%d ms)drawable (%d, %d)-(%d, %d)\n",
+ GetTickCount (), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+#endif
+
+ /*
+ * Calculate the required size of the Windows window rectangle,
+ * given the size of the Windows window client area.
+ */
+ AdjustWindowRectEx (&rcNew, dwStyle, FALSE, dwExStyle);
+
+ /* Get a rectangle describing the old Windows window */
+ GetWindowRect (hWnd, &rcOld);
+
+#if CYGMULTIWINDOW_DEBUG
+ /* Get a rectangle describing the Windows window client area */
+ GetClientRect (hWnd, &rcClient);
+
+ lpRc = &rcNew;
+ winDebug ("winPositionWindowMultiWindow - (%d ms)rcNew (%d, %d)-(%d, %d)\n",
+ GetTickCount (), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+
+ lpRc = &rcOld;
+ winDebug ("winPositionWindowMultiWindow - (%d ms)rcOld (%d, %d)-(%d, %d)\n",
+ GetTickCount (), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+
+ lpRc = &rcClient;
+ winDebug ("(%d ms)rcClient (%d, %d)-(%d, %d)\n",
+ GetTickCount (), lpRc->left, lpRc->top, lpRc->right, lpRc->bottom);
+#endif
+
+ /* Check if the old rectangle and new rectangle are the same */
+ if (!EqualRect (&rcNew, &rcOld))
+ {
+ winDebug ("winPositionWindowMultiWindow - Need to move\n");
+ winDebug ("\tMoveWindow to (%ld, %ld) - %ldx%ld\n", rcNew.left, rcNew.top,
+ rcNew.right - rcNew.left, rcNew.bottom - rcNew.top);
+
+ /* Change the position and dimensions of the Windows window */
+ MoveWindow (hWnd,
+ rcNew.left, rcNew.top,
+ rcNew.right - rcNew.left, rcNew.bottom - rcNew.top,
+ TRUE);
+ }
+ else
+ {
+ winDebug ("winPositionWindowMultiWindow - Not need to move\n");
+ }
+
+ return fResult;
+}
+
+
+/*
+ * ChangeWindowAttributes - See Porting Layer Definition - p. 37
+ */
+
+Bool
+winChangeWindowAttributesMultiWindow (WindowPtr pWin, unsigned long mask)
+{
+ Bool fResult = TRUE;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winScreenPriv(pScreen);
+
+ winDebug ("winChangeWindowAttributesMultiWindow - pWin: %08x\n", pWin);
+
+ WIN_UNWRAP(ChangeWindowAttributes);
+ fResult = (*pScreen->ChangeWindowAttributes)(pWin, mask);
+ WIN_WRAP(ChangeWindowAttributes, winChangeWindowAttributesMultiWindow);
+
+ /*
+ * NOTE: We do not currently need to do anything here.
+ */
+
+ return fResult;
+}
+
+
+/*
+ * UnmapWindow - See Porting Layer Definition - p. 37
+ * Also referred to as UnrealizeWindow
+ */
+
+Bool
+winUnmapWindowMultiWindow (WindowPtr pWin)
+{
+ Bool fResult = TRUE;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winWindowPriv(pWin);
+ winScreenPriv(pScreen);
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("winUnmapWindowMultiWindow - pWin: %08x\n", pWin);
+#endif
+
+ WIN_UNWRAP(UnrealizeWindow);
+ fResult = (*pScreen->UnrealizeWindow)(pWin);
+ WIN_WRAP(UnrealizeWindow, winUnmapWindowMultiWindow);
+
+ /* Flag that the window has been killed */
+ pWinPriv->fXKilled = TRUE;
+
+ /* Destroy the Windows window associated with this X window */
+ winDestroyWindowsWindow (pWin);
+
+ return fResult;
+}
+
+
+/*
+ * MapWindow - See Porting Layer Definition - p. 37
+ * Also referred to as RealizeWindow
+ */
+
+Bool
+winMapWindowMultiWindow (WindowPtr pWin)
+{
+ Bool fResult = TRUE;
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winWindowPriv(pWin);
+ winScreenPriv(pScreen);
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("winMapWindowMultiWindow - pWin: %08x\n", pWin);
+#endif
+
+ WIN_UNWRAP(RealizeWindow);
+ fResult = (*pScreen->RealizeWindow)(pWin);
+ WIN_WRAP(RealizeWindow, winMapWindowMultiWindow);
+
+ /* Flag that this window has not been destroyed */
+ pWinPriv->fXKilled = FALSE;
+
+ /* Refresh/redisplay the Windows window associated with this X window */
+ winUpdateWindowsWindow (pWin);
+
+ /* Update the Windows window's shape */
+ winReshapeMultiWindow (pWin);
+ winUpdateRgnMultiWindow (pWin);
+
+ return fResult;
+}
+
+
+/*
+ * ReparentWindow - See Porting Layer Definition - p. 42
+ */
+
+void
+winReparentWindowMultiWindow (WindowPtr pWin, WindowPtr pPriorParent)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winScreenPriv(pScreen);
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("winReparentMultiWindow - pWin: %08x\n", pWin);
+#endif
+
+ WIN_UNWRAP(ReparentWindow);
+ if (pScreen->ReparentWindow)
+ (*pScreen->ReparentWindow)(pWin, pPriorParent);
+ WIN_WRAP(ReparentWindow, winReparentWindowMultiWindow);
+
+ /* Update the Windows window associated with this X window */
+ winUpdateWindowsWindow (pWin);
+}
+
+
+/*
+ * RestackWindow - Shuffle the z-order of a window
+ */
+
+void
+winRestackWindowMultiWindow (WindowPtr pWin, WindowPtr pOldNextSib)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winScreenPriv(pScreen);
+
+ winDebug ("winRestackMultiWindow - %08x\n", pWin);
+
+ WIN_UNWRAP(RestackWindow);
+ if (pScreen->RestackWindow)
+ (*pScreen->RestackWindow)(pWin, pOldNextSib);
+ WIN_WRAP(RestackWindow, winRestackWindowMultiWindow);
+
+ /*
+ * Calling winReorderWindowsMultiWindow here means our window manager
+ * (i.e. Windows Explorer) has initiative to determine Z order.
+ */
+ if (pWin->nextSib != pOldNextSib)
+ winReorderWindowsMultiWindow ();
+}
+
+
+/*
+ * winCreateWindowsWindow - Create a Windows window associated with an X window
+ */
+
+void
+winCreateWindowsWindow (WindowPtr pWin)
+{
+ int iX, iY;
+ int iWidth;
+ int iHeight;
+ HWND hWnd;
+ HWND hFore = NULL;
+ winWindowPriv(pWin);
+ HICON hIcon;
+ HICON hIconSmall;
+ winPrivScreenPtr pScreenPriv = pWinPriv->pScreenPriv;
+ WinXSizeHints hints;
+ WindowPtr pDaddy;
+
+ winInitMultiWindowClass();
+
+ winDebug ("winCreateWindowsWindow - pWin: %08x\n", pWin);
+
+ iX = pWin->drawable.x + GetSystemMetrics (SM_XVIRTUALSCREEN);
+ iY = pWin->drawable.y + GetSystemMetrics (SM_YVIRTUALSCREEN);
+
+ iWidth = pWin->drawable.width;
+ iHeight = pWin->drawable.height;
+
+ if (winMultiWindowGetTransientFor (pWin, &pDaddy))
+ {
+ if (pDaddy)
+ {
+ hFore = GetForegroundWindow();
+ if (hFore && (pDaddy != (WindowPtr)GetProp(hFore, WIN_WID_PROP))) hFore = NULL;
+ }
+ }
+ else
+ {
+ /* Default positions if none specified */
+ if (!winMultiWindowGetWMNormalHints(pWin, &hints))
+ hints.flags = 0;
+ if (!(hints.flags & (USPosition|PPosition)) &&
+ !pWin->overrideRedirect)
+ {
+ iX = CW_USEDEFAULT;
+ iY = CW_USEDEFAULT;
+ }
+ }
+
+ /* Create the window */
+ /* Make it OVERLAPPED in create call since WS_POPUP doesn't support */
+ /* CW_USEDEFAULT, change back to popup after creation */
+ hWnd = CreateWindowExA (WS_EX_TOOLWINDOW, /* Extended styles */
+ WINDOW_CLASS_X, /* Class name */
+ WINDOW_TITLE_X, /* Window name */
+ WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
+ iX, /* Horizontal position */
+ iY, /* Vertical position */
+ iWidth, /* Right edge */
+ iHeight, /* Bottom edge */
+ hFore, /* Null or Parent window if transient*/
+ (HMENU) NULL, /* No menu */
+ GetModuleHandle (NULL), /* Instance handle */
+ pWin); /* ScreenPrivates */
+ if (hWnd == NULL)
+ {
+ ErrorF ("winCreateWindowsWindow - CreateWindowExA () failed: %d\n",
+ (int) GetLastError ());
+ }
+ pWinPriv->hWnd = hWnd;
+
+ /* Set application or .XWinrc defined Icons */
+ winSelectIcons(pWin, &hIcon, &hIconSmall);
+ if (hIcon) SendMessage (hWnd, WM_SETICON, ICON_BIG, (LPARAM) hIcon);
+ if (hIconSmall) SendMessage (hWnd, WM_SETICON, ICON_SMALL, (LPARAM) hIconSmall);
+
+ /* Change style back to popup, already placed... */
+ SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
+ SetWindowPos (hWnd, 0, 0, 0, 0, 0,
+ SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+ /* Make sure it gets the proper system menu for a WS_POPUP, too */
+ GetSystemMenu (hWnd, TRUE);
+
+ /* Cause any .XWinrc menus to be added in main WNDPROC */
+ PostMessage (hWnd, WM_INIT_SYS_MENU, 0, 0);
+
+ SetProp (hWnd, WIN_WID_PROP, (HANDLE) winGetWindowID(pWin));
+
+ /* Flag that this Windows window handles its own activation */
+ SetProp (hWnd, WIN_NEEDMANAGE_PROP, (HANDLE) 0);
+
+ /* Call engine-specific create window procedure */
+ (*pScreenPriv->pwinFinishCreateWindowsWindow) (pWin);
+}
+
+
+Bool winInDestroyWindowsWindow = FALSE;
+/*
+ * winDestroyWindowsWindow - Destroy a Windows window associated
+ * with an X window
+ */
+static void
+winDestroyWindowsWindow (WindowPtr pWin)
+{
+ MSG msg;
+ winWindowPriv(pWin);
+ BOOL oldstate = winInDestroyWindowsWindow;
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("winDestroyWindowsWindow\n");
+#endif
+
+ /* Bail out if the Windows window handle is invalid */
+ if (pWinPriv->hWnd == NULL)
+ return;
+
+ winInDestroyWindowsWindow = TRUE;
+
+ SetProp (pWinPriv->hWnd, WIN_WINDOW_PROP, NULL);
+ /* 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 */
+ while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
+ {
+ if (g_hDlgDepthChange == 0 || !IsDialogMessage (g_hDlgDepthChange, &msg))
+ {
+ DispatchMessage (&msg);
+ }
+ }
+
+ winInDestroyWindowsWindow = oldstate;
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("-winDestroyWindowsWindow\n");
+#endif
+}
+
+
+/*
+ * winUpdateWindowsWindow - Redisplay/redraw a Windows window
+ * associated with an X window
+ */
+
+static void
+winUpdateWindowsWindow (WindowPtr pWin)
+{
+ winWindowPriv(pWin);
+ HWND hWnd = pWinPriv->hWnd;
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("winUpdateWindowsWindow\n");
+#endif
+
+ /* Check if the Windows window's parents have been destroyed */
+ if (pWin->parent != NULL
+ && pWin->parent->parent == NULL
+ && pWin->mapped)
+ {
+ /* Create the Windows window if it has been destroyed */
+ if (hWnd == NULL)
+ {
+ winCreateWindowsWindow (pWin);
+ assert (pWinPriv->hWnd != NULL);
+ }
+
+ /* Display the window without activating it */
+ ShowWindow (pWinPriv->hWnd, SW_SHOWNOACTIVATE);
+
+ /* Send first paint message */
+ UpdateWindow (pWinPriv->hWnd);
+ }
+ else if (hWnd != NULL)
+ {
+ /* Destroy the Windows window if its parents are destroyed */
+ winDestroyWindowsWindow (pWin);
+ assert (pWinPriv->hWnd == NULL);
+ }
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("-winUpdateWindowsWindow\n");
+#endif
+}
+
+
+/*
+ * winGetWindowID -
+ */
+
+XID
+winGetWindowID (WindowPtr pWin)
+{
+ WindowIDPairRec wi = {pWin, 0};
+ ClientPtr c = wClient(pWin);
+
+ /* */
+ FindClientResourcesByType (c, RT_WINDOW, winFindWindow, &wi);
+
+#if CYGMULTIWINDOW_DEBUG
+ winDebug ("winGetWindowID - Window ID: %d\n", wi.id);
+#endif
+
+ return wi.id;
+}
+
+
+/*
+ * winFindWindow -
+ */
+
+static void
+winFindWindow (pointer value, XID id, pointer cdata)
+{
+ WindowIDPairPtr wi = (WindowIDPairPtr)cdata;
+
+ if (value == wi->value)
+ {
+ wi->id = id;
+ }
+}
+
+
+/*
+ * winReorderWindowsMultiWindow -
+ */
+
+void
+winReorderWindowsMultiWindow (void)
+{
+ HWND hwnd = NULL;
+ WindowPtr pWin = NULL;
+ WindowPtr pWinSib = NULL;
+ XID vlist[2];
+ static Bool fRestacking = FALSE; /* Avoid recusive calls to this function */
+ DWORD dwCurrentProcessID = GetCurrentProcessId ();
+ DWORD dwWindowProcessID = 0;
+
+ winDebug ("winReorderWindowsMultiWindow\n");
+
+ if (fRestacking)
+ {
+ /* It is a recusive call so immediately exit */
+ winDebug ("winReorderWindowsMultiWindow - "
+ "exit because fRestacking == TRUE\n");
+ return;
+ }
+ fRestacking = TRUE;
+
+ /* Loop through top level Window windows, descending in Z order */
+ for ( hwnd = GetTopWindow (NULL);
+ hwnd;
+ hwnd = GetNextWindow (hwnd, GW_HWNDNEXT) )
+ {
+ /* Don't take care of other Cygwin/X process's windows */
+ GetWindowThreadProcessId (hwnd, &dwWindowProcessID);
+
+ if ( GetProp (hwnd, WIN_WINDOW_PROP)
+ && (dwWindowProcessID == dwCurrentProcessID)
+ && !IsIconic (hwnd) ) /* ignore minimized windows */
+ {
+ pWinSib = pWin;
+ pWin = GetProp (hwnd, WIN_WINDOW_PROP);
+
+ if (!pWinSib)
+ { /* 1st window - raise to the top */
+ vlist[0] = Above;
+
+ ConfigureWindow (pWin, CWStackMode, vlist, wClient(pWin));
+ }
+ else
+ { /* 2nd or deeper windows - just below the previous one */
+ vlist[0] = winGetWindowID (pWinSib);
+ vlist[1] = Below;
+
+ ConfigureWindow (pWin, CWSibling | CWStackMode,
+ vlist, wClient(pWin));
+ }
+ }
+ }
+
+ fRestacking = FALSE;
+}
+
+
+/*
+ * winMinimizeWindow - Minimize in response to WM_CHANGE_STATE
+ */
+
+void
+winMinimizeWindow (Window id)
+{
+ WindowPtr pWin;
+ winPrivWinPtr pWinPriv;
+#ifdef XWIN_MULTIWINDOWEXTWM
+ win32RootlessWindowPtr pRLWinPriv;
+#endif
+ HWND hWnd;
+ ScreenPtr pScreen = NULL;
+ winPrivScreenPtr pScreenPriv = NULL;
+ winScreenInfo *pScreenInfo = NULL;
+
+ winDebug ("winMinimizeWindow\n");
+
+ dixLookupResourceByType((pointer) &pWin, id, RT_WINDOW, NullClient, DixUnknownAccess);
+ if (!pWin)
+ {
+ ErrorF("%s: NULL pWin. Leaving\n", __FUNCTION__);
+ return;
+ }
+
+ pScreen = pWin->drawable.pScreen;
+ if (pScreen) pScreenPriv = winGetScreenPriv(pScreen);
+ if (pScreenPriv) pScreenInfo = pScreenPriv->pScreenInfo;
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+ if (pScreenPriv && pScreenInfo->fInternalWM)
+ {
+ pRLWinPriv = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, FALSE);
+ hWnd = pRLWinPriv->hWnd;
+ }
+ else
+#else
+ if (pScreenPriv)
+#endif
+ {
+ pWinPriv = winGetWindowPriv (pWin);
+ hWnd = pWinPriv->hWnd;
+ }
+
+ ShowWindow (hWnd, SW_MINIMIZE);
+}
+
+
+/*
+ * CopyWindow - See Porting Layer Definition - p. 39
+ */
+void
+winCopyWindowMultiWindow (WindowPtr pWin, DDXPointRec oldpt,
+ RegionPtr oldRegion)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winScreenPriv(pScreen);
+
+ winDebug ("CopyWindowMultiWindow\n");
+
+ WIN_UNWRAP(CopyWindow);
+ (*pScreen->CopyWindow)(pWin, oldpt, oldRegion);
+ WIN_WRAP(CopyWindow, winCopyWindowMultiWindow);
+}
+
+
+/*
+ * MoveWindow - See Porting Layer Definition - p. 42
+ */
+void
+winMoveWindowMultiWindow (WindowPtr pWin, int x, int y,
+ WindowPtr pSib, VTKind kind)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winScreenPriv(pScreen);
+
+ winDebug ("MoveWindowMultiWindow to (%d, %d)\n", x, y);
+
+ WIN_UNWRAP(MoveWindow);
+ (*pScreen->MoveWindow)(pWin, x, y, pSib, kind);
+ WIN_WRAP(MoveWindow, winMoveWindowMultiWindow);
+}
+
+
+/*
+ * ResizeWindow - See Porting Layer Definition - p. 42
+ */
+void
+winResizeWindowMultiWindow (WindowPtr pWin, int x, int y, unsigned int w,
+ unsigned int h, WindowPtr pSib)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ winScreenPriv(pScreen);
+
+ winDebug ("ResizeWindowMultiWindow to (%d, %d) - %dx%d\n", x, y, w, h);
+
+ WIN_UNWRAP(ResizeWindow);
+ (*pScreen->ResizeWindow)(pWin, x, y, w, h, pSib);
+ WIN_WRAP(ResizeWindow, winResizeWindowMultiWindow);
+}
+
+
+/*
+ * winAdjustXWindow
+ *
+ * Move and resize X window with respect to corresponding Windows window.
+ * This is called from WM_MOVE/WM_SIZE handlers when the user performs
+ * any windowing operation (move, resize, minimize, maximize, restore).
+ *
+ * The functionality is the inverse of winPositionWindowMultiWindow, which
+ * adjusts Windows window with respect to X window.
+ */
+int
+winAdjustXWindow (WindowPtr pWin, HWND hwnd)
+{
+ RECT rcDraw; /* Rect made from pWin->drawable to be adjusted */
+ RECT rcWin; /* The source: WindowRect from hwnd */
+ DrawablePtr pDraw;
+ XID vlist[4];
+ LONG dX, dY, dW, dH, x, y;
+ DWORD dwStyle, dwExStyle;
+
+#define WIDTH(rc) (rc.right - rc.left)
+#define HEIGHT(rc) (rc.bottom - rc.top)
+
+ winDebug ("winAdjustXWindow\n");
+
+ if (IsIconic (hwnd))
+ {
+ winDebug ("\timmediately return because the window is iconized\n");
+ /*
+ * If the Windows window is minimized, its WindowRect has
+ * meaningless values so we don't adjust X window to it.
+ */
+ vlist[0] = 0;
+ vlist[1] = 0;
+ return ConfigureWindow (pWin, CWX | CWY, vlist, wClient(pWin));
+ }
+
+ pDraw = &pWin->drawable;
+
+ /* Calculate the window rect from the drawable */
+ x = pDraw->x + GetSystemMetrics (SM_XVIRTUALSCREEN);
+ y = pDraw->y + GetSystemMetrics (SM_YVIRTUALSCREEN);
+ SetRect (&rcDraw, x, y, x + pDraw->width, y + pDraw->height);
+ winDebug("\tDrawable extend {%d, %d, %d, %d}, {%d, %d}\n",
+ rcDraw.left, rcDraw.top, rcDraw.right, rcDraw.bottom,
+ rcDraw.right - rcDraw.left, rcDraw.bottom - rcDraw.top);
+ dwExStyle = GetWindowLongPtr (hwnd, GWL_EXSTYLE);
+ dwStyle = GetWindowLongPtr (hwnd, GWL_STYLE);
+ winDebug("\tWindowStyle: %08x %08x\n", dwStyle, dwExStyle);
+ AdjustWindowRectEx (&rcDraw, dwStyle, FALSE, dwExStyle);
+
+ /* The source of adjust */
+ GetWindowRect (hwnd, &rcWin);
+ winDebug("\tWindow extend {%d, %d, %d, %d}, {%d, %d}\n",
+ rcWin.left, rcWin.top, rcWin.right, rcWin.bottom,
+ rcWin.right - rcWin.left, rcWin.bottom - rcWin.top);
+ winDebug("\tDraw extend {%d, %d, %d, %d}, {%d, %d}\n",
+ rcDraw.left, rcDraw.top, rcDraw.right, rcDraw.bottom,
+ rcDraw.right - rcDraw.left, rcDraw.bottom - rcDraw.top);
+
+ if (EqualRect (&rcDraw, &rcWin)) {
+ /* Bail if no adjust is needed */
+ winDebug ("\treturn because already adjusted\n");
+ return 0;
+ }
+
+ /* Calculate delta values */
+ dX = rcWin.left - rcDraw.left;
+ dY = rcWin.top - rcDraw.top;
+ dW = WIDTH(rcWin) - WIDTH(rcDraw);
+ dH = HEIGHT(rcWin) - HEIGHT(rcDraw);
+
+ /*
+ * Adjust.
+ * We may only need to move (vlist[0] and [1]), or only resize
+ * ([2] and [3]) but currently we set all the parameters and leave
+ * the decision to ConfigureWindow. The reason is code simplicity.
+ */
+ vlist[0] = pDraw->x + dX - wBorderWidth(pWin);
+ vlist[1] = pDraw->y + dY - wBorderWidth(pWin);
+ vlist[2] = pDraw->width + dW;
+ vlist[3] = pDraw->height + dH;
+ winDebug ("\tConfigureWindow to (%ld, %ld) - %ldx%ld\n", vlist[0], vlist[1],
+ vlist[2], vlist[3]);
+ return ConfigureWindow (pWin, CWX | CWY | CWWidth | CWHeight,
+ vlist, wClient(pWin));
+
+#undef WIDTH
+#undef HEIGHT
+}
+
diff --git a/xorg-server/hw/xwin/winmultiwindowwm.c b/xorg-server/hw/xwin/winmultiwindowwm.c index 5e4e98b69..f4b396c48 100644 --- a/xorg-server/hw/xwin/winmultiwindowwm.c +++ b/xorg-server/hw/xwin/winmultiwindowwm.c @@ -1,1580 +1,1618 @@ -/* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - *Copyright (C) Colin Harrison 2005-2009 - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of the XFree86 Project - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from the XFree86 Project. - * - * Authors: Kensuke Matsuzaki - * Colin Harrison - */ - -/* X headers */ -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include <stdio.h> -#include <stdlib.h> -#ifndef _MSC_VER -#include <unistd.h> -#endif -#ifdef __CYGWIN__ -#include <sys/select.h> -#endif -#include <fcntl.h> -#include <setjmp.h> -#define HANDLE void * -#ifdef _MSC_VER -typedef int pid_t; -#endif -#include <pthread.h> -#undef HANDLE -#include <X11/X.h> -#include <X11/Xatom.h> -#include <X11/Xlib.h> -#include <X11/Xlocale.h> -#include <X11/Xproto.h> -#include <X11/Xutil.h> -#include <X11/cursorfont.h> -#include <X11/Xwindows.h> - -/* Local headers */ -#include "objbase.h" -#include "ddraw.h" -#include "winwindow.h" -#include "winprefs.h" -#include "window.h" -#include "pixmapstr.h" -#include "winmsg.h" -#include "windowstr.h" - -#ifdef XWIN_MULTIWINDOWEXTWM -#include <X11/extensions/windowswmstr.h> -#else -/* We need the native HWND atom for intWM, so for consistency use the - same name as extWM would if we were building with enabled... */ -#define WINDOWSWM_NATIVE_HWND "_WINDOWSWM_NATIVE_HWND" -#endif - -extern void winDebug(const char *format, ...); -extern void winReshapeMultiWindow(WindowPtr pWin); -extern void winUpdateRgnMultiWindow(WindowPtr pWin); - -/* - * Constant defines - */ - -#define WIN_CONNECT_RETRIES 5 -#define WIN_CONNECT_DELAY 5 -#ifdef HAS_DEVWINDOWS -# define WIN_MSG_QUEUE_FNAME "/dev/windows" -#endif -#define WIN_JMP_OKAY 0 -#define WIN_JMP_ERROR_IO 2 -#define AUTH_NAME "MIT-MAGIC-COOKIE-1" - - -/* - * Local structures - */ - -typedef struct _WMMsgNodeRec { - winWMMessageRec msg; - struct _WMMsgNodeRec *pNext; -} WMMsgNodeRec, *WMMsgNodePtr; - -typedef struct _WMMsgQueueRec { - struct _WMMsgNodeRec *pHead; - struct _WMMsgNodeRec *pTail; - pthread_mutex_t pmMutex; - pthread_cond_t pcNotEmpty; - int nQueueSize; -} WMMsgQueueRec, *WMMsgQueuePtr; - -typedef struct _WMInfo { - Display *pDisplay; - WMMsgQueueRec wmMsgQueue; - Atom atmWmProtos; - Atom atmWmDelete; - Atom atmPrivMap; - Bool fAllowOtherWM; -} WMInfoRec, *WMInfoPtr; - -typedef struct _WMProcArgRec { - DWORD dwScreen; - WMInfoPtr pWMInfo; - pthread_mutex_t *ppmServerStarted; -} WMProcArgRec, *WMProcArgPtr; - -typedef struct _XMsgProcArgRec { - Display *pDisplay; - DWORD dwScreen; - WMInfoPtr pWMInfo; - pthread_mutex_t *ppmServerStarted; - HWND hwndScreen; -} XMsgProcArgRec, *XMsgProcArgPtr; - - -/* - * References to external symbols - */ - -extern char *display; -extern void ErrorF (const char* /*f*/, ...); -#if defined(XCSECURITY) -extern unsigned int g_uiAuthDataLen; -extern char *g_pAuthData; -#endif - - -/* - * Prototypes for local functions - */ - -static void -PushMessage (WMMsgQueuePtr pQueue, WMMsgNodePtr pNode); - -static WMMsgNodePtr -PopMessage (WMMsgQueuePtr pQueue, WMInfoPtr pWMInfo); - -static Bool -InitQueue (WMMsgQueuePtr pQueue); - -static void -GetWindowName (Display * pDpy, Window iWin, wchar_t **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 int -winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr); - -static int -winMultiWindowWMIOErrorHandler (Display *pDisplay); - -static void * -winMultiWindowXMsgProc (void *pArg); - -static int -winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr); - -static int -winMultiWindowXMsgProcIOErrorHandler (Display *pDisplay); - -static int -winRedirectErrorHandler (Display *pDisplay, XErrorEvent *pErr); - -static void -winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg); - -static Bool -CheckAnotherWindowManager (Display *pDisplay, DWORD dwScreen); - -static void -winApplyHints (Display *pDisplay, Window iWindow, HWND hWnd, HWND *zstyle); - -void -winUpdateWindowPosition (HWND hWnd, Bool reshape, HWND *zstyle); - -/* - * Local globals - */ - -static jmp_buf g_jmpWMEntry; -static jmp_buf g_jmpXMsgProcEntry; -static Bool g_shutdown = FALSE; -static Bool redirectError = FALSE; -static Bool g_fAnotherWMRunnig = FALSE; - -/* - * PushMessage - Push a message onto the queue - */ - -static void -PushMessage (WMMsgQueuePtr pQueue, WMMsgNodePtr pNode) -{ - - /* Lock the queue mutex */ - pthread_mutex_lock (&pQueue->pmMutex); - - pNode->pNext = NULL; - - if (pQueue->pTail != NULL) - { - pQueue->pTail->pNext = pNode; - } - pQueue->pTail = pNode; - - if (pQueue->pHead == NULL) - { - pQueue->pHead = pNode; - } - - /* Increase the count of elements in the queue by one */ - ++(pQueue->nQueueSize); - - /* Release the queue mutex */ - pthread_mutex_unlock (&pQueue->pmMutex); - - /* Signal that the queue is not empty */ - pthread_cond_signal (&pQueue->pcNotEmpty); -} - - -#ifdef WINDBG -/* - * QueueSize - Return the size of the queue - */ - -static int -QueueSize (WMMsgQueuePtr pQueue) -{ - WMMsgNodePtr pNode; - int nSize = 0; - - /* Loop through all elements in the queue */ - for (pNode = pQueue->pHead; pNode != NULL; pNode = pNode->pNext) - ++nSize; - - return nSize; -} -#endif - - -/* - * PopMessage - Pop a message from the queue - */ - -static WMMsgNodePtr -PopMessage (WMMsgQueuePtr pQueue, WMInfoPtr pWMInfo) -{ - WMMsgNodePtr pNode; - - /* Lock the queue mutex */ - pthread_mutex_lock (&pQueue->pmMutex); - - /* Wait for --- */ - while (pQueue->pHead == NULL) - { - pthread_cond_wait (&pQueue->pcNotEmpty, &pQueue->pmMutex); - } - - pNode = pQueue->pHead; - if (pQueue->pHead != NULL) - { - pQueue->pHead = pQueue->pHead->pNext; - } - - if (pQueue->pTail == pNode) - { - pQueue->pTail = NULL; - } - - /* Drop the number of elements in the queue by one */ - --(pQueue->nQueueSize); - - winDebug ("Queue Size %d %d\n", pQueue->nQueueSize, QueueSize(pQueue)); - - /* Release the queue mutex */ - pthread_mutex_unlock (&pQueue->pmMutex); - - return pNode; -} - - -#if 0 -/* - * HaveMessage - - */ - -static Bool -HaveMessage (WMMsgQueuePtr pQueue, UINT msg, Window iWindow) -{ - WMMsgNodePtr pNode; - - for (pNode = pQueue->pHead; pNode != NULL; pNode = pNode->pNext) - { - if (pNode->msg.msg==msg && pNode->msg.iWindow==iWindow) - return True; - } - - return False; -} -#endif - - -/* - * InitQueue - Initialize the Window Manager message queue - */ - -static -Bool -InitQueue (WMMsgQueuePtr pQueue) -{ - /* Check if the pQueue pointer is NULL */ - if (pQueue == NULL) - { - ErrorF ("InitQueue - pQueue is NULL. Exiting.\n"); - return FALSE; - } - - /* Set the head and tail to NULL */ - pQueue->pHead = NULL; - pQueue->pTail = NULL; - - /* There are no elements initially */ - pQueue->nQueueSize = 0; - - winDebug ("InitQueue - Queue Size %d %d\n", pQueue->nQueueSize, - QueueSize(pQueue)); - - winDebug ("InitQueue - Calling pthread_mutex_init\n"); - - /* Create synchronization objects */ - pthread_mutex_init (&pQueue->pmMutex, NULL); - - winDebug ("InitQueue - pthread_mutex_init returned\n"); - winDebug ("InitQueue - Calling pthread_cond_init\n"); - - pthread_cond_init (&pQueue->pcNotEmpty, NULL); - - winDebug ("InitQueue - pthread_cond_init returned\n"); - - return TRUE; -} - - -/* - * GetWindowName - Retrieve the title of an X Window - */ - -static void -GetWindowName (Display *pDisplay, Window iWin, wchar_t **ppName) -{ - int nResult, nNum; - char **ppList; - char *pszReturnData; - int iLen, i; - XTextProperty xtpName; - - winDebug ("GetWindowName\n"); - - /* Intialize ppName to NULL */ - *ppName = NULL; - - /* Try to get --- */ - nResult = XGetWMName (pDisplay, iWin, &xtpName); - if (!nResult || !xtpName.value || !xtpName.nitems) - { - ErrorF ("GetWindowName - XGetWMName failed. No name.\n"); - return; - } - - if (Xutf8TextPropertyToTextList (pDisplay, &xtpName, &ppList, &nNum) >= Success && nNum > 0 && *ppList) - { - iLen = 0; - for (i = 0; i < nNum; i++) iLen += strlen(ppList[i]); - pszReturnData = (char *) malloc (iLen + 1); - pszReturnData[0] = '\0'; - for (i = 0; i < nNum; i++) strcat (pszReturnData, ppList[i]); - } - else - { - pszReturnData = (char *) malloc (1); - pszReturnData[0] = '\0'; - } - iLen = MultiByteToWideChar (CP_UTF8, 0, pszReturnData, -1, NULL, 0); - *ppName = (wchar_t*)malloc(sizeof(wchar_t)*(iLen + 1)); - MultiByteToWideChar (CP_UTF8, 0, pszReturnData, -1, *ppName, iLen); - XFree (xtpName.value); - if (ppList) XFreeStringList (ppList); - free (pszReturnData); - - winDebug ("GetWindowName - Returning\n"); -} - - -/* - * Send a message to the X server from the WM thread - */ - -static int -SendXMessage (Display *pDisplay, Window iWin, Atom atmType, long nData) -{ - XEvent e; - - /* Prepare the X event structure */ - e.type = ClientMessage; - e.xclient.window = iWin; - e.xclient.message_type = atmType; - e.xclient.format = 32; - e.xclient.data.l[0] = nData; - e.xclient.data.l[1] = CurrentTime; - - /* Send the event to X */ - return XSendEvent (pDisplay, iWin, False, NoEventMask, &e); -} - - -/* - * Updates the name of a HWND according to its X WM_NAME property - */ - -static void -UpdateName (WMInfoPtr pWMInfo, Window iWindow) -{ - wchar_t *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, - XA_INTEGER,//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) - { - SetWindowTextW (hWnd, pszName); - winUpdateIcon (iWindow); - } - - free (pszName); - } -} - - -#if 0 -/* - * Fix up any differences between the X11 and Win32 window stacks - * starting at the window passed in - */ -static void -PreserveWin32Stack(WMInfoPtr pWMInfo, Window iWindow, UINT direction) -{ - Atom atmType; - int fmtRet; - unsigned long items, remain; - HWND hWnd, *retHwnd; - DWORD myWinProcID, winProcID; - Window xWindow; - WINDOWPLACEMENT wndPlace; - - hWnd = NULL; - /* See if we can get the cached HWND for this window... */ - if (XGetWindowProperty (pWMInfo->pDisplay, - iWindow, - pWMInfo->atmPrivMap, - 0, - 1, - False, - XA_INTEGER,//pWMInfo->atmPrivMap, - &atmType, - &fmtRet, - &items, - &remain, - (unsigned char **) &retHwnd) == Success) - { - if (retHwnd) - { - hWnd = *retHwnd; - XFree (retHwnd); - } - } - - if (!hWnd) return; - - GetWindowThreadProcessId (hWnd, &myWinProcID); - hWnd = GetNextWindow (hWnd, direction); - - while (hWnd) { - GetWindowThreadProcessId (hWnd, &winProcID); - if (winProcID == myWinProcID) - { - wndPlace.length = sizeof(WINDOWPLACEMENT); - GetWindowPlacement (hWnd, &wndPlace); - if ( !(wndPlace.showCmd==SW_HIDE || - wndPlace.showCmd==SW_MINIMIZE) ) - { - xWindow = (Window)GetProp (hWnd, WIN_WID_PROP); - if (xWindow) - { - if (direction==GW_HWNDPREV) - XRaiseWindow (pWMInfo->pDisplay, xWindow); - else - XLowerWindow (pWMInfo->pDisplay, xWindow); - } - } - } - hWnd = GetNextWindow(hWnd, direction); - } -} -#endif /* PreserveWin32Stack */ - - -/* - * winMultiWindowWMProc - */ - -static void * -winMultiWindowWMProc (void *pArg) -{ - WMProcArgPtr pProcArg = (WMProcArgPtr)pArg; - WMInfoPtr pWMInfo = pProcArg->pWMInfo; - - /* Initialize the Window Manager */ - winInitMultiWindowWM (pWMInfo, pProcArg); - - winDebug ("winMultiWindowWMProc ()\n"); - - /* Loop until we explicity break out */ - for (;;) - { - WMMsgNodePtr pNode; - - if(g_fAnotherWMRunnig)/* Another Window manager exists. */ - { - Sleep (1000); - continue; - } - - /* Pop a message off of our queue */ - pNode = PopMessage (&pWMInfo->wmMsgQueue, pWMInfo); - if (pNode == NULL) - { - /* Bail if PopMessage returns without a message */ - /* NOTE: Remember that PopMessage is a blocking function. */ - ErrorF ("winMultiWindowWMProc - Queue is Empty? Exiting.\n"); - pthread_exit (NULL); - } - - winDebug ("winMultiWindowWMProc - %d ms MSG: %d ID: %d\n", - GetTickCount (), (int)pNode->msg.msg, (int)pNode->msg.dwID); - - /* Branch on the message type */ - switch (pNode->msg.msg) - { - case WM_WM_RAISE: - winDebug ("\tWM_WM_RAISE\n"); - /* Raise the window */ - XRaiseWindow (pWMInfo->pDisplay, pNode->msg.iWindow); - break; - - case WM_WM_LOWER: - winDebug ("\tWM_WM_LOWER\n"); - - /* Lower the window */ - XLowerWindow (pWMInfo->pDisplay, pNode->msg.iWindow); - break; - - case WM_WM_MAP: - winDebug ("\tWM_WM_MAP\n"); - /* Put a note as to the HWND associated with this Window */ - XChangeProperty (pWMInfo->pDisplay, - pNode->msg.iWindow, - pWMInfo->atmPrivMap, - XA_INTEGER,//pWMInfo->atmPrivMap, - 32, - PropModeReplace, - (unsigned char *) &(pNode->msg.hwndWindow), - 1); - UpdateName (pWMInfo, pNode->msg.iWindow); - winUpdateIcon (pNode->msg.iWindow); - { - HWND zstyle = HWND_NOTOPMOST; - winApplyHints (pWMInfo->pDisplay, pNode->msg.iWindow, pNode->msg.hwndWindow, &zstyle); - winUpdateWindowPosition (pNode->msg.hwndWindow, TRUE, &zstyle); - } - break; - - case WM_WM_MAP2: - winDebug ("\tWM_WM_MAP2\n"); - - XChangeProperty (pWMInfo->pDisplay, - pNode->msg.iWindow, - pWMInfo->atmPrivMap, - XA_INTEGER,//pWMInfo->atmPrivMap, - 32, - PropModeReplace, - (unsigned char *) &(pNode->msg.hwndWindow), - 1); - break; - - case WM_WM_MAP3: - winDebug ("\tWM_WM_MAP3\n"); - - /* Put a note as to the HWND associated with this Window */ - XChangeProperty (pWMInfo->pDisplay, - pNode->msg.iWindow, - pWMInfo->atmPrivMap, - XA_INTEGER,//pWMInfo->atmPrivMap, - 32, - PropModeReplace, - (unsigned char *) &(pNode->msg.hwndWindow), - 1); - UpdateName (pWMInfo, pNode->msg.iWindow); - winUpdateIcon (pNode->msg.iWindow); - { - HWND zstyle = HWND_NOTOPMOST; - winApplyHints (pWMInfo->pDisplay, pNode->msg.iWindow, pNode->msg.hwndWindow, &zstyle); - winUpdateWindowPosition (pNode->msg.hwndWindow, TRUE, &zstyle); - } - break; - - case WM_WM_UNMAP: - winDebug ("\tWM_WM_UNMAP\n"); - - /* Unmap the window */ - XUnmapWindow (pWMInfo->pDisplay, pNode->msg.iWindow); - break; - - case WM_WM_KILL: - winDebug ("\tWM_WM_KILL\n"); - { - int i, n, found = 0; - Atom *protocols; - - /* --- */ - if (XGetWMProtocols (pWMInfo->pDisplay, - pNode->msg.iWindow, - &protocols, - &n)) - { - for (i = 0; i < n; ++i) - if (protocols[i] == pWMInfo->atmWmDelete) - ++found; - - XFree (protocols); - } - - /* --- */ - if (found) - SendXMessage (pWMInfo->pDisplay, - pNode->msg.iWindow, - pWMInfo->atmWmProtos, - pWMInfo->atmWmDelete); - else - XKillClient (pWMInfo->pDisplay, - pNode->msg.iWindow); - } - break; - - case WM_WM_ACTIVATE: - winDebug ("\tWM_WM_ACTIVATE\n"); - - /* Set the input focus */ - XSetInputFocus (pWMInfo->pDisplay, - pNode->msg.iWindow, - RevertToPointerRoot, - CurrentTime); - break; - - 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: - ErrorF ("winMultiWindowWMProc - Unknown Message. Exiting.\n"); - pthread_exit (NULL); - break; - } - - /* Free the retrieved message */ - free (pNode); - - /* Flush any pending events on our display */ - XFlush (pWMInfo->pDisplay); - } - - /* Free the condition variable */ - pthread_cond_destroy (&pWMInfo->wmMsgQueue.pcNotEmpty); - - /* Free the mutex variable */ - pthread_mutex_destroy (&pWMInfo->wmMsgQueue.pmMutex); - - /* Free the passed-in argument */ - free (pProcArg); - - winDebug("-winMultiWindowWMProc ()\n"); - return NULL; -} - - -/* - * X message procedure - */ - -static void * -winMultiWindowXMsgProc (void *pArg) -{ - winWMMessageRec msg; - XMsgProcArgPtr pProcArg = (XMsgProcArgPtr) pArg; - char pszDisplay[512]; - int iRetries; - XEvent event; - Atom atmWmName; - Atom atmWmHints; - Atom atmWmChange; - int iReturn; - XIconSize *xis; - - winDebug ("winMultiWindowXMsgProc - Hello\n"); - - /* Check that argument pointer is not invalid */ - if (pProcArg == NULL) - { - ErrorF ("winMultiWindowXMsgProc - pProcArg is NULL. Exiting.\n"); - pthread_exit (NULL); - } - - winDebug ("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. " - "Exiting.\n", - iReturn); - pthread_exit (NULL); - } - - winDebug ("winMultiWindowXMsgProc - pthread_mutex_lock () returned.\n"); - - /* See if X supports the current locale */ - if (XSupportsLocale () == False) - { - ErrorF ("winMultiWindowXMsgProc - Locale not supported by X. " - "Exiting.\n"); - pthread_exit (NULL); - } - - /* Release the server started mutex */ - pthread_mutex_unlock (pProcArg->ppmServerStarted); - - winDebug ("winMultiWindowXMsgProc - pthread_mutex_unlock () returned.\n"); - - /* Set jump point for IO Error exits */ - iReturn = setjmp (g_jmpXMsgProcEntry); - - /* Check if we should continue operations */ - if (iReturn != WIN_JMP_ERROR_IO - && iReturn != WIN_JMP_OKAY) - { - /* setjmp returned an unknown value, exit */ - ErrorF ("winInitMultiWindowXMsgProc - setjmp returned: %d. Exiting.\n", - iReturn); - pthread_exit (NULL); - } - else if (iReturn == WIN_JMP_ERROR_IO) - { - ErrorF ("winInitMultiWindowXMsgProc - Caught IO Error. Exiting.\n"); - pthread_exit (NULL); - } - - /* Install our error handler */ - XSetErrorHandler (winMultiWindowXMsgProcErrorHandler); - XSetIOErrorHandler (winMultiWindowXMsgProcIOErrorHandler); - - /* Setup the display connection string x */ - snprintf (pszDisplay, - 512, "127.0.0.1:%s.%d", display, (int)pProcArg->dwScreen); - - /* Print the display connection string */ - winDebug ("winMultiWindowXMsgProc - DISPLAY=%s\n", pszDisplay); - - /* Initialize retry count */ - iRetries = 0; - - /* Open the X display */ - do - { - /* Try to open the display */ - pProcArg->pDisplay = XOpenDisplay (pszDisplay); - if (pProcArg->pDisplay == NULL) - { - winDebug ("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 ("winMultiWindowXMsgProc - Failed opening the display. " - "Exiting.\n"); - pthread_exit (NULL); - } - - winDebug ("winMultiWindowXMsgProc - XOpenDisplay () returned and " - "successfully opened the display.\n"); - - /* Check if another window manager is already running */ - if (pProcArg->pWMInfo->fAllowOtherWM) - { - g_fAnotherWMRunnig = CheckAnotherWindowManager (pProcArg->pDisplay, pProcArg->dwScreen); - } else { - redirectError = FALSE; - XSetErrorHandler (winRedirectErrorHandler); - XSelectInput(pProcArg->pDisplay, - RootWindow (pProcArg->pDisplay, pProcArg->dwScreen), - SubstructureNotifyMask | ButtonPressMask); - XSync (pProcArg->pDisplay, 0); - XSetErrorHandler (winMultiWindowXMsgProcErrorHandler); - if (redirectError) - { - ErrorF ("winMultiWindowXMsgProc - " - "another window manager is running. Exiting.\n"); - pthread_exit (NULL); - } - g_fAnotherWMRunnig = FALSE; - } - - /* 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) - { - if (g_shutdown) - break; - - if (pProcArg->pWMInfo->fAllowOtherWM && !XPending (pProcArg->pDisplay)) - { - if (CheckAnotherWindowManager (pProcArg->pDisplay, pProcArg->dwScreen)) - { - if (!g_fAnotherWMRunnig) - { - g_fAnotherWMRunnig = TRUE; - SendMessage(*(HWND*)pProcArg->hwndScreen, WM_UNMANAGE, 0, 0); - } - } - else - { - if (g_fAnotherWMRunnig) - { - g_fAnotherWMRunnig = FALSE; - SendMessage(*(HWND*)pProcArg->hwndScreen, WM_MANAGE, 0, 0); - } - } - Sleep (500); - continue; - } - - /* Fetch next event */ - XNextEvent (pProcArg->pDisplay, &event); - - /* Branch on event type */ - if (event.type == MapNotify /* CreateNotify */) - { - XWindowAttributes attr; - - XSelectInput (pProcArg->pDisplay, - event.xcreatewindow.window, - PropertyChangeMask); - - /* Get the window attributes */ - XGetWindowAttributes (pProcArg->pDisplay, - event.xcreatewindow.window, - &attr); - - if (!attr.override_redirect && attr.class != InputOnly) - XSetWindowBorderWidth(pProcArg->pDisplay, - event.xcreatewindow.window, - 0); - } - 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) - { - winDebug ("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); - } - } - - XCloseDisplay (pProcArg->pDisplay); - pthread_exit (NULL); - return NULL; -} - - -/* - * winInitWM - Entry point for the X server to spawn - * the Window Manager thread. Called from - * winscrinit.c/winFinishScreenInitFB (). - */ - -Bool -winInitWM (void **ppWMInfo, - pthread_t *ptWMProc, - pthread_t *ptXMsgProc, - pthread_mutex_t *ppmServerStarted, - int dwScreen, - HWND hwndScreen, - BOOL allowOtherWM) -{ - 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) - { - ErrorF ("winInitWM - malloc failed.\n"); - return FALSE; - } - - /* Zero the allocated memory */ - ZeroMemory (pArg, sizeof (WMProcArgRec)); - ZeroMemory (pWMInfo, sizeof (WMInfoRec)); - ZeroMemory (pXMsgArg, sizeof (XMsgProcArgRec)); - - /* Set a return pointer to the Window Manager info structure */ - *ppWMInfo = pWMInfo; - pWMInfo->fAllowOtherWM = allowOtherWM; - - /* Setup the argument structure for the thread function */ - pArg->dwScreen = dwScreen; - pArg->pWMInfo = pWMInfo; - pArg->ppmServerStarted = ppmServerStarted; - - /* Intialize the message queue */ - if (!InitQueue (&pWMInfo->wmMsgQueue)) - { - ErrorF ("winInitWM - InitQueue () failed.\n"); - return FALSE; - } - - /* Spawn a thread for the Window Manager */ - if (pthread_create (ptWMProc, NULL, winMultiWindowWMProc, pArg)) - { - /* Bail if thread creation failed */ - 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; - pXMsgArg->hwndScreen = hwndScreen; - if (pthread_create (ptXMsgProc, NULL, winMultiWindowXMsgProc, pXMsgArg)) - { - /* Bail if thread creation failed */ - ErrorF ("winInitWM - pthread_create failed on XMSG.\n"); - return FALSE; - } - - winDebug ("winInitWM - Returning.\n"); - - return TRUE; -} - - -/* - * Window manager thread - setup - */ - -static void -winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg) -{ - int iRetries = 0; - char pszDisplay[512]; - int iReturn; - - winDebug ("winInitMultiWindowWM - Hello\n"); - - /* Check that argument pointer is not invalid */ - if (pProcArg == NULL) - { - ErrorF ("winInitMultiWindowWM - pProcArg is NULL. Exiting.\n"); - pthread_exit (NULL); - } - - winDebug ("winInitMultiWindowWM - Calling pthread_mutex_lock ()\n"); - - /* Grab our garbage mutex to satisfy pthread_cond_wait */ - iReturn = pthread_mutex_lock (pProcArg->ppmServerStarted); - if (iReturn != 0) - { - ErrorF ("winInitMultiWindowWM - pthread_mutex_lock () failed: %d. " - "Exiting.\n", - iReturn); - pthread_exit (NULL); - } - - winDebug ("winInitMultiWindowWM - pthread_mutex_lock () returned.\n"); - - /* See if X supports the current locale */ - if (XSupportsLocale () == False) - { - ErrorF ("winInitMultiWindowWM - Locale not supported by X. Exiting.\n"); - pthread_exit (NULL); - } - - /* Release the server started mutex */ - pthread_mutex_unlock (pProcArg->ppmServerStarted); - - winDebug ("winInitMultiWindowWM - pthread_mutex_unlock () returned.\n"); - - /* Set jump point for IO Error exits */ - iReturn = setjmp (g_jmpWMEntry); - - /* Check if we should continue operations */ - if (iReturn != WIN_JMP_ERROR_IO - && iReturn != WIN_JMP_OKAY) - { - /* setjmp returned an unknown value, exit */ - ErrorF ("winInitMultiWindowWM - setjmp returned: %d. Exiting.\n", - iReturn); - pthread_exit (NULL); - } - else if (iReturn == WIN_JMP_ERROR_IO) - { - ErrorF ("winInitMultiWindowWM - Caught IO Error. Exiting.\n"); - pthread_exit (NULL); - } - - /* Install our error handler */ - XSetErrorHandler (winMultiWindowWMErrorHandler); - XSetIOErrorHandler (winMultiWindowWMIOErrorHandler); - - /* Setup the display connection string x */ - snprintf (pszDisplay, - 512, - "127.0.0.1:%s.%d", - display, - (int) pProcArg->dwScreen); - - /* Print the display connection string */ - winDebug ("winInitMultiWindowWM - DISPLAY=%s\n", pszDisplay); - -#if defined(XCSECURITY) - /* Use our generated cookie for authentication */ - XSetAuthorization (AUTH_NAME, - strlen (AUTH_NAME), - g_pAuthData, - g_uiAuthDataLen); -#endif - - /* Open the X display */ - do - { - /* Try to open the display */ - pWMInfo->pDisplay = XOpenDisplay (pszDisplay); - if (pWMInfo->pDisplay == NULL) - { - ErrorF ("winInitMultiWindowWM - Could not open display, try: %d, " - "sleeping: %d\n\f", - iRetries + 1, WIN_CONNECT_DELAY); - ++iRetries; - sleep (WIN_CONNECT_DELAY); - continue; - } - else - break; - } - while (pWMInfo->pDisplay == NULL && iRetries < WIN_CONNECT_RETRIES); - - /* Make sure that the display opened */ - if (pWMInfo->pDisplay == NULL) - { - ErrorF ("winInitMultiWindowWM - Failed opening the display. " - "Exiting.\n"); - pthread_exit (NULL); - } - - winDebug ("winInitMultiWindowWM - XOpenDisplay () returned and " - "successfully opened the display.\n"); - - - /* Create some atoms */ - pWMInfo->atmWmProtos = XInternAtom (pWMInfo->pDisplay, - "WM_PROTOCOLS", - False); - pWMInfo->atmWmDelete = XInternAtom (pWMInfo->pDisplay, - "WM_DELETE_WINDOW", - False); - - pWMInfo->atmPrivMap = XInternAtom (pWMInfo->pDisplay, - WINDOWSWM_NATIVE_HWND, - False); - - - if (1) { - Cursor cursor = XCreateFontCursor (pWMInfo->pDisplay, XC_left_ptr); - if (cursor) - { - XDefineCursor (pWMInfo->pDisplay, DefaultRootWindow(pWMInfo->pDisplay), cursor); - XFreeCursor (pWMInfo->pDisplay, cursor); - } - } -} - - -/* - * winSendMessageToWM - Send a message from the X thread to the WM thread - */ - -void -winSendMessageToWM (void *pWMInfo, winWMMessagePtr pMsg) -{ - WMMsgNodePtr pNode; - - winDebug ("winSendMessageToWM ()\n"); - - pNode = (WMMsgNodePtr)malloc(sizeof(WMMsgNodeRec)); - if (pNode != NULL) - { - memcpy (&pNode->msg, pMsg, sizeof(winWMMessageRec)); - PushMessage (&((WMInfoPtr)pWMInfo)->wmMsgQueue, pNode); - } -} - - -/* - * Window manager error handler - */ - -static int -winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr) -{ - char pszErrorMsg[100]; - - if (pErr->request_code == X_ChangeWindowAttributes - && pErr->error_code == BadAccess) - { - ErrorF ("winMultiWindowWMErrorHandler - ChangeWindowAttributes " - "BadAccess.\n"); - return 0; - } - - XGetErrorText (pDisplay, - pErr->error_code, - pszErrorMsg, - sizeof (pszErrorMsg)); - ErrorF ("winMultiWindowWMErrorHandler - ERROR: %s\n" - " errorCode %d\n" - " serial %d\n" - " resourceID 0x%x\n" - " majorCode %d\n" - " minorCode %d\n" - , pszErrorMsg - , pErr->error_code - , pErr->serial - , pErr->resourceid - , pErr->request_code - , pErr->minor_code); - - return 0; -} - - -/* - * Window manager IO error handler - */ - -static int -winMultiWindowWMIOErrorHandler (Display *pDisplay) -{ - ErrorF ("\nwinMultiWindowWMIOErrorHandler!\n\n"); - - if (g_shutdown) - pthread_exit(NULL); - - /* Restart at the main entry point */ - longjmp (g_jmpWMEntry, WIN_JMP_ERROR_IO); - - return 0; -} - - -/* - * X message procedure error handler - */ - -static int -winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr) -{ - char pszErrorMsg[100]; - - XGetErrorText (pDisplay, - pErr->error_code, - pszErrorMsg, - sizeof (pszErrorMsg)); - ErrorF ("winMultiWindowXMsgProcErrorHandler - ERROR: %s\n" - " errorCode %d\n" - " serial %d\n" - " resourceID 0x%x\n" - " majorCode %d\n" - " minorCode %d\n" - , pszErrorMsg - , pErr->error_code - , pErr->serial - , pErr->resourceid - , pErr->request_code - , pErr->minor_code); - - return 0; -} - - -/* - * X message procedure IO error handler - */ - -static int -winMultiWindowXMsgProcIOErrorHandler (Display *pDisplay) -{ - ErrorF ("\nwinMultiWindowXMsgProcIOErrorHandler!\n\n"); - - /* Restart at the main entry point */ - longjmp (g_jmpXMsgProcEntry, WIN_JMP_ERROR_IO); - - return 0; -} - - -/* - * Catch RedirectError to detect other window manager running - */ - -static int -winRedirectErrorHandler (Display *pDisplay, XErrorEvent *pErr) -{ - redirectError = TRUE; - return 0; -} - - -/* - * Check if another window manager is running - */ - -static Bool -CheckAnotherWindowManager (Display *pDisplay, DWORD dwScreen) -{ - redirectError = FALSE; - XSetErrorHandler (winRedirectErrorHandler); - XSelectInput(pDisplay, RootWindow (pDisplay, dwScreen), - // SubstructureNotifyMask | ButtonPressMask - ColormapChangeMask | EnterWindowMask | PropertyChangeMask | - SubstructureRedirectMask | KeyPressMask | - ButtonPressMask | ButtonReleaseMask); - XSync (pDisplay, 0); - XSetErrorHandler (winMultiWindowXMsgProcErrorHandler); - XSelectInput(pDisplay, RootWindow (pDisplay, dwScreen), - SubstructureNotifyMask); - XSync (pDisplay, 0); - if (redirectError) - { - //ErrorF ("CheckAnotherWindowManager() - another window manager is running. Exiting.\n"); - return TRUE; - } - else - { - return FALSE; - } -} - -/* - * Notify the MWM thread we're exiting and not to reconnect - */ - -void -winDeinitMultiWindowWM (void) -{ - winDebug ("winDeinitMultiWindowWM - Noting shutdown in progress\n"); - g_shutdown = TRUE; -} - -/* Windows window styles */ -#define HINT_NOFRAME (1l<<0) -#define HINT_BORDER (1L<<1) -#define HINT_SIZEBOX (1l<<2) -#define HINT_CAPTION (1l<<3) -/* These two are used on their own */ -#define HINT_MAX (1L<<0) -#define HINT_MIN (1L<<1) - -static void -winApplyHints (Display *pDisplay, Window iWindow, HWND hWnd, HWND *zstyle) -{ - static Atom windowState, motif_wm_hints, windowType; - static Atom hiddenState, fullscreenState, belowState, aboveState; - static Atom dockWindow; - static int generation; - Atom type, *pAtom = NULL; - int format; - unsigned long hint = 0, maxmin = 0, style, nitems = 0 , left = 0; - WindowPtr pWin = GetProp (hWnd, WIN_WINDOW_PROP); - MwmHints *mwm_hint = NULL; - - if (!hWnd) return; - if (!IsWindow (hWnd)) return; - - if (generation != serverGeneration) { - generation = serverGeneration; - windowState = XInternAtom(pDisplay, "_NET_WM_STATE", False); - motif_wm_hints = XInternAtom(pDisplay, "_MOTIF_WM_HINTS", False); - windowType = XInternAtom(pDisplay, "_NET_WM_WINDOW_TYPE", False); - hiddenState = XInternAtom(pDisplay, "_NET_WM_STATE_HIDDEN", False); - fullscreenState = XInternAtom(pDisplay, "_NET_WM_STATE_FULLSCREEN", False); - belowState = XInternAtom(pDisplay, "_NET_WM_STATE_BELOW", False); - aboveState = XInternAtom(pDisplay, "_NET_WM_STATE_ABOVE", False); - dockWindow = XInternAtom(pDisplay, "_NET_WM_WINDOW_TYPE_DOCK", False); - } - - if (XGetWindowProperty(pDisplay, iWindow, windowState, 0L, - 1L, False, XA_ATOM, &type, &format, - &nitems, &left, (unsigned char **)&pAtom) == Success) - { - if (pAtom && nitems == 1) - { - if (*pAtom == hiddenState) maxmin |= HINT_MIN; - else if (*pAtom == fullscreenState) maxmin |= HINT_MAX; - if (*pAtom == belowState) *zstyle = HWND_BOTTOM; - else if (*pAtom == aboveState) *zstyle = HWND_TOPMOST; - } - if (pAtom) XFree(pAtom); - } - - nitems = left = 0; - if (XGetWindowProperty(pDisplay, iWindow, motif_wm_hints, 0L, - PropMwmHintsElements, False, motif_wm_hints, &type, &format, - &nitems, &left, (unsigned char **)&mwm_hint) == Success) - { - if (mwm_hint && nitems == PropMwmHintsElements && (mwm_hint->flags & MwmHintsDecorations)) - { - if (!mwm_hint->decorations) hint |= HINT_NOFRAME; - else if (!(mwm_hint->decorations & MwmDecorAll)) - { - if (mwm_hint->decorations & MwmDecorBorder) hint |= HINT_BORDER; - if (mwm_hint->decorations & MwmDecorHandle) hint |= HINT_SIZEBOX; - if (mwm_hint->decorations & MwmDecorTitle) hint |= HINT_CAPTION; - } - } - if (mwm_hint) XFree(mwm_hint); - } - - nitems = left = 0; - pAtom = NULL; - if (XGetWindowProperty(pDisplay, iWindow, windowType, 0L, - 1L, False, XA_ATOM, &type, &format, - &nitems, &left, (unsigned char **)&pAtom) == Success) - { - if (pAtom && nitems == 1) - { - if (*pAtom == dockWindow) - { - hint = (hint & ~HINT_NOFRAME) | HINT_SIZEBOX; /* Xming puts a sizebox on dock windows */ - *zstyle = HWND_TOPMOST; - } - } - if (pAtom) XFree(pAtom); - } - - /* Apply Styles, overriding hint settings from above */ - style = winOverrideStyle((unsigned long)pWin); - if (style & STYLE_TOPMOST) *zstyle = HWND_TOPMOST; - else if (style & STYLE_MAXIMIZE) maxmin = (hint & ~HINT_MIN) | HINT_MAX; - else if (style & STYLE_MINIMIZE) maxmin = (hint & ~HINT_MAX) | HINT_MIN; - else if (style & STYLE_BOTTOM) *zstyle = HWND_BOTTOM; - - if (maxmin & HINT_MAX) SendMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0); - else if (maxmin & HINT_MIN) SendMessage(hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0); - - if (style & STYLE_NOTITLE) - hint = (hint & ~HINT_NOFRAME & ~HINT_BORDER & ~HINT_CAPTION) | HINT_SIZEBOX; - else if (style & STYLE_OUTLINE) - hint = (hint & ~HINT_NOFRAME & ~HINT_SIZEBOX & ~HINT_CAPTION) | HINT_BORDER; - else if (style & STYLE_NOFRAME) - hint = (hint & ~HINT_BORDER & ~HINT_CAPTION & ~HINT_SIZEBOX) | HINT_NOFRAME; - - style = GetWindowLongPtr(hWnd, GWL_STYLE) & ~WS_CAPTION & ~WS_SIZEBOX; /* Just in case */ - if (!style) return; - if (!hint) /* All on, but no resize of children is allowed */ - style = style | WS_CAPTION | (GetParent(hWnd) ? 0 : WS_SIZEBOX); - else if (hint & HINT_NOFRAME); /* All off, so do nothing */ - else style = style | ((hint & HINT_BORDER) ? WS_BORDER : 0) | - ((hint & HINT_SIZEBOX) ? (GetParent(hWnd) ? 0 : WS_SIZEBOX) : 0) | - ((hint & HINT_CAPTION) ? WS_CAPTION : 0); - SetWindowLongPtr (hWnd, GWL_STYLE, style); -} - -void -winUpdateWindowPosition (HWND hWnd, Bool reshape, HWND *zstyle) -{ - int iX, iY, iWidth, iHeight; - int iDx, iDy; - RECT rcNew; - WindowPtr pWin = GetProp (hWnd, WIN_WINDOW_PROP); - DrawablePtr pDraw = NULL; - - if (!pWin) return; - pDraw = &pWin->drawable; - if (!pDraw) return; - - /* Get the X and Y location of the X window */ - 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; - iHeight = pWin->drawable.height; - - /* Setup a rectangle with the X window position and size */ - SetRect (&rcNew, iX, iY, iX + iWidth, iY + iHeight); - - AdjustWindowRectEx (&rcNew, GetWindowLongPtr (hWnd, GWL_STYLE), FALSE, WS_EX_APPWINDOW); - - /* Don't allow window decoration to disappear off to top-left as a result of this adjustment */ - if (rcNew.left < GetSystemMetrics(SM_XVIRTUALSCREEN)) - { - iDx = GetSystemMetrics(SM_XVIRTUALSCREEN) - rcNew.left; - rcNew.left += iDx; - rcNew.right += iDx; - } - - if (rcNew.top < GetSystemMetrics(SM_YVIRTUALSCREEN)) - { - iDy = GetSystemMetrics(SM_YVIRTUALSCREEN) - rcNew.top; - rcNew.top += iDy; - rcNew.bottom += iDy; - } - - /* Position the Windows window */ - SetWindowPos (hWnd, *zstyle, rcNew.left, rcNew.top, - rcNew.right - rcNew.left, rcNew.bottom - rcNew.top, - 0); - - if (reshape) - { - winReshapeMultiWindow(pWin); - winUpdateRgnMultiWindow(pWin); - } -} +/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *Copyright (C) Colin Harrison 2005-2009
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Kensuke Matsuzaki
+ * Colin Harrison
+ */
+
+/* X headers */
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#ifdef __CYGWIN__
+#include <sys/select.h>
+#endif
+#include <fcntl.h>
+#include <setjmp.h>
+#define HANDLE void *
+#ifdef _MSC_VER
+typedef int pid_t;
+#endif
+#include <pthread.h>
+#undef HANDLE
+#include <X11/X.h>
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
+#include <X11/Xlocale.h>
+#include <X11/Xproto.h>
+#include <X11/Xutil.h>
+#include <X11/cursorfont.h>
+#include <X11/Xwindows.h>
+
+/* Local headers */
+#include "objbase.h"
+#include "ddraw.h"
+#include "winwindow.h"
+#include "winprefs.h"
+#include "window.h"
+#include "pixmapstr.h"
+#include "winmsg.h"
+#include "windowstr.h"
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+#include <X11/extensions/windowswmstr.h>
+#else
+/* We need the native HWND atom for intWM, so for consistency use the
+ same name as extWM would if we were building with enabled... */
+#define WINDOWSWM_NATIVE_HWND "_WINDOWSWM_NATIVE_HWND"
+#endif
+
+extern void winDebug(const char *format, ...);
+extern void winReshapeMultiWindow(WindowPtr pWin);
+extern void winUpdateRgnMultiWindow(WindowPtr pWin);
+
+/*
+ * Constant defines
+ */
+
+#define WIN_CONNECT_RETRIES 5
+#define WIN_CONNECT_DELAY 5
+#ifdef HAS_DEVWINDOWS
+# define WIN_MSG_QUEUE_FNAME "/dev/windows"
+#endif
+#define WIN_JMP_OKAY 0
+#define WIN_JMP_ERROR_IO 2
+
+/*
+ * Local structures
+ */
+
+typedef struct _WMMsgNodeRec {
+ winWMMessageRec msg;
+ struct _WMMsgNodeRec *pNext;
+} WMMsgNodeRec, *WMMsgNodePtr;
+
+typedef struct _WMMsgQueueRec {
+ struct _WMMsgNodeRec *pHead;
+ struct _WMMsgNodeRec *pTail;
+ pthread_mutex_t pmMutex;
+ pthread_cond_t pcNotEmpty;
+ int nQueueSize;
+} WMMsgQueueRec, *WMMsgQueuePtr;
+
+typedef struct _WMInfo {
+ Display *pDisplay;
+ WMMsgQueueRec wmMsgQueue;
+ Atom atmWmProtos;
+ Atom atmWmDelete;
+ Atom atmPrivMap;
+ Bool fAllowOtherWM;
+} WMInfoRec, *WMInfoPtr;
+
+typedef struct _WMProcArgRec {
+ DWORD dwScreen;
+ WMInfoPtr pWMInfo;
+ pthread_mutex_t *ppmServerStarted;
+} WMProcArgRec, *WMProcArgPtr;
+
+typedef struct _XMsgProcArgRec {
+ Display *pDisplay;
+ DWORD dwScreen;
+ WMInfoPtr pWMInfo;
+ pthread_mutex_t *ppmServerStarted;
+ HWND hwndScreen;
+} XMsgProcArgRec, *XMsgProcArgPtr;
+
+
+/*
+ * References to external symbols
+ */
+
+extern char *display;
+extern void ErrorF (const char* /*f*/, ...);
+
+/*
+ * Prototypes for local functions
+ */
+
+static void
+PushMessage (WMMsgQueuePtr pQueue, WMMsgNodePtr pNode);
+
+static WMMsgNodePtr
+PopMessage (WMMsgQueuePtr pQueue, WMInfoPtr pWMInfo);
+
+static Bool
+InitQueue (WMMsgQueuePtr pQueue);
+
+static void
+GetWindowName (Display * pDpy, Window iWin, wchar_t **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 int
+winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr);
+
+static int
+winMultiWindowWMIOErrorHandler (Display *pDisplay);
+
+static void *
+winMultiWindowXMsgProc (void *pArg);
+
+static int
+winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr);
+
+static int
+winMultiWindowXMsgProcIOErrorHandler (Display *pDisplay);
+
+static int
+winRedirectErrorHandler (Display *pDisplay, XErrorEvent *pErr);
+
+static void
+winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg);
+
+static Bool
+CheckAnotherWindowManager (Display *pDisplay, DWORD dwScreen);
+
+static void
+winApplyHints (Display *pDisplay, Window iWindow, HWND hWnd, HWND *zstyle);
+
+void
+winUpdateWindowPosition (HWND hWnd, Bool reshape, HWND *zstyle);
+
+/*
+ * Local globals
+ */
+
+static jmp_buf g_jmpWMEntry;
+static jmp_buf g_jmpXMsgProcEntry;
+static Bool g_shutdown = FALSE;
+static Bool redirectError = FALSE;
+static Bool g_fAnotherWMRunning = FALSE;
+
+/*
+ * PushMessage - Push a message onto the queue
+ */
+
+static void
+PushMessage (WMMsgQueuePtr pQueue, WMMsgNodePtr pNode)
+{
+
+ /* Lock the queue mutex */
+ pthread_mutex_lock (&pQueue->pmMutex);
+
+ pNode->pNext = NULL;
+
+ if (pQueue->pTail != NULL)
+ {
+ pQueue->pTail->pNext = pNode;
+ }
+ pQueue->pTail = pNode;
+
+ if (pQueue->pHead == NULL)
+ {
+ pQueue->pHead = pNode;
+ }
+
+ /* Increase the count of elements in the queue by one */
+ ++(pQueue->nQueueSize);
+
+ /* Release the queue mutex */
+ pthread_mutex_unlock (&pQueue->pmMutex);
+
+ /* Signal that the queue is not empty */
+ pthread_cond_signal (&pQueue->pcNotEmpty);
+}
+
+
+#ifdef WINDBG
+/*
+ * QueueSize - Return the size of the queue
+ */
+
+static int
+QueueSize (WMMsgQueuePtr pQueue)
+{
+ WMMsgNodePtr pNode;
+ int nSize = 0;
+
+ /* Loop through all elements in the queue */
+ for (pNode = pQueue->pHead; pNode != NULL; pNode = pNode->pNext)
+ ++nSize;
+
+ return nSize;
+}
+#endif
+
+
+/*
+ * PopMessage - Pop a message from the queue
+ */
+
+static WMMsgNodePtr
+PopMessage (WMMsgQueuePtr pQueue, WMInfoPtr pWMInfo)
+{
+ WMMsgNodePtr pNode;
+
+ /* Lock the queue mutex */
+ pthread_mutex_lock (&pQueue->pmMutex);
+
+ /* Wait for --- */
+ while (pQueue->pHead == NULL)
+ {
+ pthread_cond_wait (&pQueue->pcNotEmpty, &pQueue->pmMutex);
+ }
+
+ pNode = pQueue->pHead;
+ if (pQueue->pHead != NULL)
+ {
+ pQueue->pHead = pQueue->pHead->pNext;
+ }
+
+ if (pQueue->pTail == pNode)
+ {
+ pQueue->pTail = NULL;
+ }
+
+ /* Drop the number of elements in the queue by one */
+ --(pQueue->nQueueSize);
+
+ winDebug ("Queue Size %d %d\n", pQueue->nQueueSize, QueueSize(pQueue));
+
+ /* Release the queue mutex */
+ pthread_mutex_unlock (&pQueue->pmMutex);
+
+ return pNode;
+}
+
+
+#if 0
+/*
+ * HaveMessage -
+ */
+
+static Bool
+HaveMessage (WMMsgQueuePtr pQueue, UINT msg, Window iWindow)
+{
+ WMMsgNodePtr pNode;
+
+ for (pNode = pQueue->pHead; pNode != NULL; pNode = pNode->pNext)
+ {
+ if (pNode->msg.msg==msg && pNode->msg.iWindow==iWindow)
+ return True;
+ }
+
+ return False;
+}
+#endif
+
+
+/*
+ * InitQueue - Initialize the Window Manager message queue
+ */
+
+static
+Bool
+InitQueue (WMMsgQueuePtr pQueue)
+{
+ /* Check if the pQueue pointer is NULL */
+ if (pQueue == NULL)
+ {
+ ErrorF ("InitQueue - pQueue is NULL. Exiting.\n");
+ return FALSE;
+ }
+
+ /* Set the head and tail to NULL */
+ pQueue->pHead = NULL;
+ pQueue->pTail = NULL;
+
+ /* There are no elements initially */
+ pQueue->nQueueSize = 0;
+
+ winDebug ("InitQueue - Queue Size %d %d\n", pQueue->nQueueSize,
+ QueueSize(pQueue));
+
+ winDebug ("InitQueue - Calling pthread_mutex_init\n");
+
+ /* Create synchronization objects */
+ pthread_mutex_init (&pQueue->pmMutex, NULL);
+
+ winDebug ("InitQueue - pthread_mutex_init returned\n");
+ winDebug ("InitQueue - Calling pthread_cond_init\n");
+
+ pthread_cond_init (&pQueue->pcNotEmpty, NULL);
+
+ winDebug ("InitQueue - pthread_cond_init returned\n");
+
+ return TRUE;
+}
+
+
+/*
+ * GetWindowName - Retrieve the title of an X Window
+ */
+
+static void
+GetWindowName (Display *pDisplay, Window iWin, wchar_t **ppName)
+{
+ int nResult, nNum;
+ char **ppList;
+ char *pszReturnData;
+ int iLen, i;
+ XTextProperty xtpName;
+
+ winDebug ("GetWindowName\n");
+
+ /* Intialize ppName to NULL */
+ *ppName = NULL;
+
+ /* Try to get --- */
+ nResult = XGetWMName (pDisplay, iWin, &xtpName);
+ if (!nResult || !xtpName.value || !xtpName.nitems)
+ {
+ ErrorF ("GetWindowName - XGetWMName failed. No name.\n");
+ return;
+ }
+
+ if (Xutf8TextPropertyToTextList (pDisplay, &xtpName, &ppList, &nNum) >= Success && nNum > 0 && *ppList)
+ {
+ iLen = 0;
+ for (i = 0; i < nNum; i++) iLen += strlen(ppList[i]);
+ pszReturnData = (char *) malloc (iLen + 1);
+ pszReturnData[0] = '\0';
+ for (i = 0; i < nNum; i++) strcat (pszReturnData, ppList[i]);
+ }
+ else
+ {
+ pszReturnData = (char *) malloc (1);
+ pszReturnData[0] = '\0';
+ }
+ iLen = MultiByteToWideChar (CP_UTF8, 0, pszReturnData, -1, NULL, 0);
+ *ppName = (wchar_t*)malloc(sizeof(wchar_t)*(iLen + 1));
+ MultiByteToWideChar (CP_UTF8, 0, pszReturnData, -1, *ppName, iLen);
+ XFree (xtpName.value);
+ if (ppList) XFreeStringList (ppList);
+ free (pszReturnData);
+
+ winDebug ("GetWindowName - Returning\n");
+}
+
+
+/*
+ * Send a message to the X server from the WM thread
+ */
+
+static int
+SendXMessage (Display *pDisplay, Window iWin, Atom atmType, long nData)
+{
+ XEvent e;
+
+ /* Prepare the X event structure */
+ e.type = ClientMessage;
+ e.xclient.window = iWin;
+ e.xclient.message_type = atmType;
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = nData;
+ e.xclient.data.l[1] = CurrentTime;
+
+ /* Send the event to X */
+ return XSendEvent (pDisplay, iWin, False, NoEventMask, &e);
+}
+
+
+/*
+ * Updates the name of a HWND according to its X WM_NAME property
+ */
+
+static void
+UpdateName (WMInfoPtr pWMInfo, Window iWindow)
+{
+ wchar_t *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,
+ XA_INTEGER,//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)
+ {
+ SetWindowTextW (hWnd, pszName);
+ winUpdateIcon (iWindow);
+ }
+
+ free (pszName);
+ }
+}
+
+
+#if 0
+/*
+ * Fix up any differences between the X11 and Win32 window stacks
+ * starting at the window passed in
+ */
+static void
+PreserveWin32Stack(WMInfoPtr pWMInfo, Window iWindow, UINT direction)
+{
+ Atom atmType;
+ int fmtRet;
+ unsigned long items, remain;
+ HWND hWnd, *retHwnd;
+ DWORD myWinProcID, winProcID;
+ Window xWindow;
+ WINDOWPLACEMENT wndPlace;
+
+ hWnd = NULL;
+ /* See if we can get the cached HWND for this window... */
+ if (XGetWindowProperty (pWMInfo->pDisplay,
+ iWindow,
+ pWMInfo->atmPrivMap,
+ 0,
+ 1,
+ False,
+ XA_INTEGER,//pWMInfo->atmPrivMap,
+ &atmType,
+ &fmtRet,
+ &items,
+ &remain,
+ (unsigned char **) &retHwnd) == Success)
+ {
+ if (retHwnd)
+ {
+ hWnd = *retHwnd;
+ XFree (retHwnd);
+ }
+ }
+
+ if (!hWnd) return;
+
+ GetWindowThreadProcessId (hWnd, &myWinProcID);
+ hWnd = GetNextWindow (hWnd, direction);
+
+ while (hWnd) {
+ GetWindowThreadProcessId (hWnd, &winProcID);
+ if (winProcID == myWinProcID)
+ {
+ wndPlace.length = sizeof(WINDOWPLACEMENT);
+ GetWindowPlacement (hWnd, &wndPlace);
+ if ( !(wndPlace.showCmd==SW_HIDE ||
+ wndPlace.showCmd==SW_MINIMIZE) )
+ {
+ xWindow = (Window)GetProp (hWnd, WIN_WID_PROP);
+ if (xWindow)
+ {
+ if (direction==GW_HWNDPREV)
+ XRaiseWindow (pWMInfo->pDisplay, xWindow);
+ else
+ XLowerWindow (pWMInfo->pDisplay, xWindow);
+ }
+ }
+ }
+ hWnd = GetNextWindow(hWnd, direction);
+ }
+}
+#endif /* PreserveWin32Stack */
+
+
+/*
+ * winMultiWindowWMProc
+ */
+
+static void *
+winMultiWindowWMProc (void *pArg)
+{
+ WMProcArgPtr pProcArg = (WMProcArgPtr)pArg;
+ WMInfoPtr pWMInfo = pProcArg->pWMInfo;
+
+ /* Initialize the Window Manager */
+ winInitMultiWindowWM (pWMInfo, pProcArg);
+
+ winDebug ("winMultiWindowWMProc ()\n");
+
+ /* Loop until we explicity break out */
+ for (;;)
+ {
+ WMMsgNodePtr pNode;
+
+ if(g_fAnotherWMRunning)/* Another Window manager exists. */
+ {
+ Sleep (1000);
+ continue;
+ }
+
+ /* Pop a message off of our queue */
+ pNode = PopMessage (&pWMInfo->wmMsgQueue, pWMInfo);
+ if (pNode == NULL)
+ {
+ /* Bail if PopMessage returns without a message */
+ /* NOTE: Remember that PopMessage is a blocking function. */
+ ErrorF ("winMultiWindowWMProc - Queue is Empty? Exiting.\n");
+ pthread_exit (NULL);
+ }
+
+ winDebug ("winMultiWindowWMProc - %d ms MSG: %d ID: %d\n",
+ GetTickCount (), (int)pNode->msg.msg, (int)pNode->msg.dwID);
+
+ /* Branch on the message type */
+ switch (pNode->msg.msg)
+ {
+ case WM_WM_RAISE:
+ winDebug ("\tWM_WM_RAISE\n");
+ /* Raise the window */
+ XRaiseWindow (pWMInfo->pDisplay, pNode->msg.iWindow);
+ break;
+
+ case WM_WM_LOWER:
+ winDebug ("\tWM_WM_LOWER\n");
+
+ /* Lower the window */
+ XLowerWindow (pWMInfo->pDisplay, pNode->msg.iWindow);
+ break;
+
+ case WM_WM_MAP:
+ winDebug ("\tWM_WM_MAP\n");
+ /* Put a note as to the HWND associated with this Window */
+ XChangeProperty (pWMInfo->pDisplay,
+ pNode->msg.iWindow,
+ pWMInfo->atmPrivMap,
+ XA_INTEGER,//pWMInfo->atmPrivMap,
+ 32,
+ PropModeReplace,
+ (unsigned char *) &(pNode->msg.hwndWindow),
+ 1);
+ UpdateName (pWMInfo, pNode->msg.iWindow);
+ winUpdateIcon (pNode->msg.iWindow);
+ {
+ HWND zstyle = HWND_NOTOPMOST;
+ winApplyHints (pWMInfo->pDisplay, pNode->msg.iWindow, pNode->msg.hwndWindow, &zstyle);
+ winUpdateWindowPosition (pNode->msg.hwndWindow, TRUE, &zstyle);
+ }
+ break;
+
+ case WM_WM_MAP2:
+ winDebug ("\tWM_WM_MAP2\n");
+
+ XChangeProperty (pWMInfo->pDisplay,
+ pNode->msg.iWindow,
+ pWMInfo->atmPrivMap,
+ XA_INTEGER,//pWMInfo->atmPrivMap,
+ 32,
+ PropModeReplace,
+ (unsigned char *) &(pNode->msg.hwndWindow),
+ 1);
+ break;
+
+ case WM_WM_MAP3:
+ winDebug ("\tWM_WM_MAP3\n");
+
+ /* Put a note as to the HWND associated with this Window */
+ XChangeProperty (pWMInfo->pDisplay,
+ pNode->msg.iWindow,
+ pWMInfo->atmPrivMap,
+ XA_INTEGER,//pWMInfo->atmPrivMap,
+ 32,
+ PropModeReplace,
+ (unsigned char *) &(pNode->msg.hwndWindow),
+ 1);
+ UpdateName (pWMInfo, pNode->msg.iWindow);
+ winUpdateIcon (pNode->msg.iWindow);
+ {
+ HWND zstyle = HWND_NOTOPMOST;
+ winApplyHints (pWMInfo->pDisplay, pNode->msg.iWindow, pNode->msg.hwndWindow, &zstyle);
+ winUpdateWindowPosition (pNode->msg.hwndWindow, TRUE, &zstyle);
+ }
+ break;
+
+ case WM_WM_UNMAP:
+ winDebug ("\tWM_WM_UNMAP\n");
+
+ /* Unmap the window */
+ XUnmapWindow (pWMInfo->pDisplay, pNode->msg.iWindow);
+ break;
+
+ case WM_WM_KILL:
+ winDebug ("\tWM_WM_KILL\n");
+ {
+ int i, n, found = 0;
+ Atom *protocols;
+
+ /* --- */
+ if (XGetWMProtocols (pWMInfo->pDisplay,
+ pNode->msg.iWindow,
+ &protocols,
+ &n))
+ {
+ for (i = 0; i < n; ++i)
+ if (protocols[i] == pWMInfo->atmWmDelete)
+ ++found;
+
+ XFree (protocols);
+ }
+
+ /* --- */
+ if (found)
+ SendXMessage (pWMInfo->pDisplay,
+ pNode->msg.iWindow,
+ pWMInfo->atmWmProtos,
+ pWMInfo->atmWmDelete);
+ else
+ XKillClient (pWMInfo->pDisplay,
+ pNode->msg.iWindow);
+ }
+ break;
+
+ case WM_WM_ACTIVATE:
+ winDebug ("\tWM_WM_ACTIVATE\n");
+
+ /* Set the input focus */
+ XSetInputFocus (pWMInfo->pDisplay,
+ pNode->msg.iWindow,
+ RevertToPointerRoot,
+ CurrentTime);
+ break;
+
+ 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:
+ ErrorF ("winMultiWindowWMProc - Unknown Message. Exiting.\n");
+ pthread_exit (NULL);
+ break;
+ }
+
+ /* Free the retrieved message */
+ free (pNode);
+
+ /* Flush any pending events on our display */
+ XFlush (pWMInfo->pDisplay);
+ }
+
+ /* Free the condition variable */
+ pthread_cond_destroy (&pWMInfo->wmMsgQueue.pcNotEmpty);
+
+ /* Free the mutex variable */
+ pthread_mutex_destroy (&pWMInfo->wmMsgQueue.pmMutex);
+
+ /* Free the passed-in argument */
+ free (pProcArg);
+
+ winDebug("-winMultiWindowWMProc ()\n");
+ return NULL;
+}
+
+
+/*
+ * X message procedure
+ */
+
+static void *
+winMultiWindowXMsgProc (void *pArg)
+{
+ winWMMessageRec msg;
+ XMsgProcArgPtr pProcArg = (XMsgProcArgPtr) pArg;
+ char pszDisplay[512];
+ int iRetries;
+ XEvent event;
+ Atom atmWmName;
+ Atom atmWmHints;
+ Atom atmWmChange;
+ int iReturn;
+ XIconSize *xis;
+
+ winDebug ("winMultiWindowXMsgProc - Hello\n");
+
+ /* Check that argument pointer is not invalid */
+ if (pProcArg == NULL)
+ {
+ ErrorF ("winMultiWindowXMsgProc - pProcArg is NULL. Exiting.\n");
+ pthread_exit (NULL);
+ }
+
+ winDebug ("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. "
+ "Exiting.\n",
+ iReturn);
+ pthread_exit (NULL);
+ }
+
+ winDebug ("winMultiWindowXMsgProc - pthread_mutex_lock () returned.\n");
+
+ /* See if X supports the current locale */
+ if (XSupportsLocale () == False)
+ {
+ ErrorF ("winMultiWindowXMsgProc - Locale not supported by X. "
+ "Exiting.\n");
+ pthread_exit (NULL);
+ }
+
+ /* Release the server started mutex */
+ pthread_mutex_unlock (pProcArg->ppmServerStarted);
+
+ winDebug ("winMultiWindowXMsgProc - pthread_mutex_unlock () returned.\n");
+
+ /* Set jump point for IO Error exits */
+ iReturn = setjmp (g_jmpXMsgProcEntry);
+
+ /* Check if we should continue operations */
+ if (iReturn != WIN_JMP_ERROR_IO
+ && iReturn != WIN_JMP_OKAY)
+ {
+ /* setjmp returned an unknown value, exit */
+ ErrorF ("winInitMultiWindowXMsgProc - setjmp returned: %d. Exiting.\n",
+ iReturn);
+ pthread_exit (NULL);
+ }
+ else if (iReturn == WIN_JMP_ERROR_IO)
+ {
+ ErrorF ("winInitMultiWindowXMsgProc - Caught IO Error. Exiting.\n");
+ pthread_exit (NULL);
+ }
+
+ /* Install our error handler */
+ XSetErrorHandler (winMultiWindowXMsgProcErrorHandler);
+ XSetIOErrorHandler (winMultiWindowXMsgProcIOErrorHandler);
+
+ /* Setup the display connection string x */
+ snprintf (pszDisplay,
+ 512, "127.0.0.1:%s.%d", display, (int)pProcArg->dwScreen);
+
+ /* Print the display connection string */
+ winDebug ("winMultiWindowXMsgProc - DISPLAY=%s\n", pszDisplay);
+
+ /* Use our generated cookie for authentication */
+ winSetAuthorization();
+
+ /* Initialize retry count */
+ iRetries = 0;
+
+ /* Open the X display */
+ do
+ {
+ /* Try to open the display */
+ pProcArg->pDisplay = XOpenDisplay (pszDisplay);
+ if (pProcArg->pDisplay == NULL)
+ {
+ winDebug ("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 ("winMultiWindowXMsgProc - Failed opening the display. "
+ "Exiting.\n");
+ pthread_exit (NULL);
+ }
+
+ winDebug ("winMultiWindowXMsgProc - XOpenDisplay () returned and "
+ "successfully opened the display.\n");
+
+ /* Check if another window manager is already running */
+ g_fAnotherWMRunning = CheckAnotherWindowManager (pProcArg->pDisplay, pProcArg->dwScreen);
+
+ if (g_fAnotherWMRunning && !pProcArg->pWMInfo->fAllowOtherWM)
+ {
+ ErrorF ("winMultiWindowXMsgProc - "
+ "another window manager is running. Exiting.\n");
+ pthread_exit (NULL);
+ }
+
+ /* 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);
+
+ /*
+ iiimxcf had a bug until 2009-04-27, assuming that the
+ WM_STATE atom exists, causing clients to fail with
+ a BadAtom X error if it doesn't.
+
+ Since this is on in the default Solaris 10 install,
+ workaround this by making sure it does exist...
+ */
+ XInternAtom(pProcArg->pDisplay, "WM_STATE", 0);
+
+ /* Loop until we explicitly break out */
+ while (1)
+ {
+ if (g_shutdown)
+ break;
+
+ if (pProcArg->pWMInfo->fAllowOtherWM && !XPending (pProcArg->pDisplay))
+ {
+ if (CheckAnotherWindowManager (pProcArg->pDisplay, pProcArg->dwScreen))
+ {
+ if (!g_fAnotherWMRunning)
+ {
+ g_fAnotherWMRunning = TRUE;
+ SendMessage(*(HWND*)pProcArg->hwndScreen, WM_UNMANAGE, 0, 0);
+ }
+ }
+ else
+ {
+ if (g_fAnotherWMRunning)
+ {
+ g_fAnotherWMRunning = FALSE;
+ SendMessage(*(HWND*)pProcArg->hwndScreen, WM_MANAGE, 0, 0);
+ }
+ }
+ Sleep (500);
+ continue;
+ }
+
+ /* Fetch next event */
+ XNextEvent (pProcArg->pDisplay, &event);
+
+ /* Branch on event type */
+ if (event.type == MapNotify /* CreateNotify */)
+ {
+ XWindowAttributes attr;
+
+ XSelectInput (pProcArg->pDisplay,
+ event.xcreatewindow.window,
+ PropertyChangeMask);
+
+ /* Get the window attributes */
+ XGetWindowAttributes (pProcArg->pDisplay,
+ event.xcreatewindow.window,
+ &attr);
+
+ if (!attr.override_redirect && attr.class != InputOnly)
+ XSetWindowBorderWidth(pProcArg->pDisplay,
+ event.xcreatewindow.window,
+ 0);
+ }
+ else if (event.type == MapNotify)
+ {
+ /* Fake a reparentNotify event as SWT/Motif expects a
+ Window Manager to reparent a top-level window when
+ it is mapped and waits until they do.
+
+ We don't actually need to reparent, as the frame is
+ a native window, not an X window
+
+ We do this on MapNotify, not MapRequest like a real
+ Window Manager would, so we don't have do get involved
+ in actually mapping the window via it's (non-existent)
+ parent...
+
+ See sourceware bugzilla #9848
+ */
+
+ XWindowAttributes attr;
+ Window root;
+ Window parent;
+ Window *children;
+ unsigned int nchildren;
+
+ if (XGetWindowAttributes(event.xmap.display,
+ event.xmap.window,
+ &attr) &&
+ XQueryTree(event.xmap.display,
+ event.xmap.window,
+ &root, &parent, &children, &nchildren))
+ {
+ if (children) XFree(children);
+
+ /*
+ It's a top-level window if the parent window is a root window
+ Only non-override_redirect windows can get reparented
+ */
+ if ((attr.root == parent) && !event.xmap.override_redirect)
+ {
+ XEvent event_send;
+
+ event_send.type = ReparentNotify;
+ event_send.xreparent.event = event.xmap.window;
+ event_send.xreparent.window = event.xmap.window;
+ event_send.xreparent.parent = parent;
+ event_send.xreparent.x = attr.x;
+ event_send.xreparent.y = attr.y;
+
+ XSendEvent(event.xmap.display,
+ event.xmap.window,
+ True, StructureNotifyMask,
+ &event_send);
+ }
+ }
+ }
+ 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)
+ {
+ winDebug ("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);
+ }
+ }
+
+ XCloseDisplay (pProcArg->pDisplay);
+ pthread_exit (NULL);
+ return NULL;
+}
+
+
+/*
+ * winInitWM - Entry point for the X server to spawn
+ * the Window Manager thread. Called from
+ * winscrinit.c/winFinishScreenInitFB ().
+ */
+
+Bool
+winInitWM (void **ppWMInfo,
+ pthread_t *ptWMProc,
+ pthread_t *ptXMsgProc,
+ pthread_mutex_t *ppmServerStarted,
+ int dwScreen,
+ HWND hwndScreen,
+ BOOL allowOtherWM)
+{
+ 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)
+ {
+ ErrorF ("winInitWM - malloc failed.\n");
+ return FALSE;
+ }
+
+ /* Zero the allocated memory */
+ ZeroMemory (pArg, sizeof (WMProcArgRec));
+ ZeroMemory (pWMInfo, sizeof (WMInfoRec));
+ ZeroMemory (pXMsgArg, sizeof (XMsgProcArgRec));
+
+ /* Set a return pointer to the Window Manager info structure */
+ *ppWMInfo = pWMInfo;
+ pWMInfo->fAllowOtherWM = allowOtherWM;
+
+ /* Setup the argument structure for the thread function */
+ pArg->dwScreen = dwScreen;
+ pArg->pWMInfo = pWMInfo;
+ pArg->ppmServerStarted = ppmServerStarted;
+
+ /* Intialize the message queue */
+ if (!InitQueue (&pWMInfo->wmMsgQueue))
+ {
+ ErrorF ("winInitWM - InitQueue () failed.\n");
+ return FALSE;
+ }
+
+ /* Spawn a thread for the Window Manager */
+ if (pthread_create (ptWMProc, NULL, winMultiWindowWMProc, pArg))
+ {
+ /* Bail if thread creation failed */
+ 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;
+ pXMsgArg->hwndScreen = hwndScreen;
+ if (pthread_create (ptXMsgProc, NULL, winMultiWindowXMsgProc, pXMsgArg))
+ {
+ /* Bail if thread creation failed */
+ ErrorF ("winInitWM - pthread_create failed on XMSG.\n");
+ return FALSE;
+ }
+
+ winDebug ("winInitWM - Returning.\n");
+
+ return TRUE;
+}
+
+
+/*
+ * Window manager thread - setup
+ */
+
+static void
+winInitMultiWindowWM (WMInfoPtr pWMInfo, WMProcArgPtr pProcArg)
+{
+ int iRetries = 0;
+ char pszDisplay[512];
+ int iReturn;
+
+ winDebug ("winInitMultiWindowWM - Hello\n");
+
+ /* Check that argument pointer is not invalid */
+ if (pProcArg == NULL)
+ {
+ ErrorF ("winInitMultiWindowWM - pProcArg is NULL. Exiting.\n");
+ pthread_exit (NULL);
+ }
+
+ winDebug ("winInitMultiWindowWM - Calling pthread_mutex_lock ()\n");
+
+ /* Grab our garbage mutex to satisfy pthread_cond_wait */
+ iReturn = pthread_mutex_lock (pProcArg->ppmServerStarted);
+ if (iReturn != 0)
+ {
+ ErrorF ("winInitMultiWindowWM - pthread_mutex_lock () failed: %d. "
+ "Exiting.\n",
+ iReturn);
+ pthread_exit (NULL);
+ }
+
+ winDebug ("winInitMultiWindowWM - pthread_mutex_lock () returned.\n");
+
+ /* See if X supports the current locale */
+ if (XSupportsLocale () == False)
+ {
+ ErrorF ("winInitMultiWindowWM - Locale not supported by X. Exiting.\n");
+ pthread_exit (NULL);
+ }
+
+ /* Release the server started mutex */
+ pthread_mutex_unlock (pProcArg->ppmServerStarted);
+
+ winDebug ("winInitMultiWindowWM - pthread_mutex_unlock () returned.\n");
+
+ /* Set jump point for IO Error exits */
+ iReturn = setjmp (g_jmpWMEntry);
+
+ /* Check if we should continue operations */
+ if (iReturn != WIN_JMP_ERROR_IO
+ && iReturn != WIN_JMP_OKAY)
+ {
+ /* setjmp returned an unknown value, exit */
+ ErrorF ("winInitMultiWindowWM - setjmp returned: %d. Exiting.\n",
+ iReturn);
+ pthread_exit (NULL);
+ }
+ else if (iReturn == WIN_JMP_ERROR_IO)
+ {
+ ErrorF ("winInitMultiWindowWM - Caught IO Error. Exiting.\n");
+ pthread_exit (NULL);
+ }
+
+ /* Install our error handler */
+ XSetErrorHandler (winMultiWindowWMErrorHandler);
+ XSetIOErrorHandler (winMultiWindowWMIOErrorHandler);
+
+ /* Setup the display connection string x */
+ snprintf (pszDisplay,
+ 512,
+ "127.0.0.1:%s.%d",
+ display,
+ (int) pProcArg->dwScreen);
+
+ /* Print the display connection string */
+ winDebug ("winInitMultiWindowWM - DISPLAY=%s\n", pszDisplay);
+
+ /* Use our generated cookie for authentication */
+ winSetAuthorization();
+
+ /* Open the X display */
+ do
+ {
+ /* Try to open the display */
+ pWMInfo->pDisplay = XOpenDisplay (pszDisplay);
+ if (pWMInfo->pDisplay == NULL)
+ {
+ ErrorF ("winInitMultiWindowWM - Could not open display, try: %d, "
+ "sleeping: %d\n\f",
+ iRetries + 1, WIN_CONNECT_DELAY);
+ ++iRetries;
+ sleep (WIN_CONNECT_DELAY);
+ continue;
+ }
+ else
+ break;
+ }
+ while (pWMInfo->pDisplay == NULL && iRetries < WIN_CONNECT_RETRIES);
+
+ /* Make sure that the display opened */
+ if (pWMInfo->pDisplay == NULL)
+ {
+ ErrorF ("winInitMultiWindowWM - Failed opening the display. "
+ "Exiting.\n");
+ pthread_exit (NULL);
+ }
+
+ winDebug ("winInitMultiWindowWM - XOpenDisplay () returned and "
+ "successfully opened the display.\n");
+
+
+ /* Create some atoms */
+ pWMInfo->atmWmProtos = XInternAtom (pWMInfo->pDisplay,
+ "WM_PROTOCOLS",
+ False);
+ pWMInfo->atmWmDelete = XInternAtom (pWMInfo->pDisplay,
+ "WM_DELETE_WINDOW",
+ False);
+
+ pWMInfo->atmPrivMap = XInternAtom (pWMInfo->pDisplay,
+ WINDOWSWM_NATIVE_HWND,
+ False);
+
+
+ if (1) {
+ Cursor cursor = XCreateFontCursor (pWMInfo->pDisplay, XC_left_ptr);
+ if (cursor)
+ {
+ XDefineCursor (pWMInfo->pDisplay, DefaultRootWindow(pWMInfo->pDisplay), cursor);
+ XFreeCursor (pWMInfo->pDisplay, cursor);
+ }
+ }
+}
+
+
+/*
+ * winSendMessageToWM - Send a message from the X thread to the WM thread
+ */
+
+void
+winSendMessageToWM (void *pWMInfo, winWMMessagePtr pMsg)
+{
+ WMMsgNodePtr pNode;
+
+ winDebug ("winSendMessageToWM ()\n");
+
+ pNode = (WMMsgNodePtr)malloc(sizeof(WMMsgNodeRec));
+ if (pNode != NULL)
+ {
+ memcpy (&pNode->msg, pMsg, sizeof(winWMMessageRec));
+ PushMessage (&((WMInfoPtr)pWMInfo)->wmMsgQueue, pNode);
+ }
+}
+
+
+/*
+ * Window manager error handler
+ */
+
+static int
+winMultiWindowWMErrorHandler (Display *pDisplay, XErrorEvent *pErr)
+{
+ char pszErrorMsg[100];
+
+ if (pErr->request_code == X_ChangeWindowAttributes
+ && pErr->error_code == BadAccess)
+ {
+ ErrorF ("winMultiWindowWMErrorHandler - ChangeWindowAttributes "
+ "BadAccess.\n");
+ return 0;
+ }
+
+ XGetErrorText (pDisplay,
+ pErr->error_code,
+ pszErrorMsg,
+ sizeof (pszErrorMsg));
+ ErrorF ("winMultiWindowWMErrorHandler - ERROR: %s\n"
+ " errorCode %d\n"
+ " serial %d\n"
+ " resourceID 0x%x\n"
+ " majorCode %d\n"
+ " minorCode %d\n"
+ , pszErrorMsg
+ , pErr->error_code
+ , pErr->serial
+ , pErr->resourceid
+ , pErr->request_code
+ , pErr->minor_code);
+
+ return 0;
+}
+
+
+/*
+ * Window manager IO error handler
+ */
+
+static int
+winMultiWindowWMIOErrorHandler (Display *pDisplay)
+{
+ ErrorF ("\nwinMultiWindowWMIOErrorHandler!\n\n");
+
+ if (g_shutdown)
+ pthread_exit(NULL);
+
+ /* Restart at the main entry point */
+ longjmp (g_jmpWMEntry, WIN_JMP_ERROR_IO);
+
+ return 0;
+}
+
+
+/*
+ * X message procedure error handler
+ */
+
+static int
+winMultiWindowXMsgProcErrorHandler (Display *pDisplay, XErrorEvent *pErr)
+{
+ char pszErrorMsg[100];
+
+ XGetErrorText (pDisplay,
+ pErr->error_code,
+ pszErrorMsg,
+ sizeof (pszErrorMsg));
+ ErrorF ("winMultiWindowXMsgProcErrorHandler - ERROR: %s\n"
+ " errorCode %d\n"
+ " serial %d\n"
+ " resourceID 0x%x\n"
+ " majorCode %d\n"
+ " minorCode %d\n"
+ , pszErrorMsg
+ , pErr->error_code
+ , pErr->serial
+ , pErr->resourceid
+ , pErr->request_code
+ , pErr->minor_code);
+
+ return 0;
+}
+
+
+/*
+ * X message procedure IO error handler
+ */
+
+static int
+winMultiWindowXMsgProcIOErrorHandler (Display *pDisplay)
+{
+ ErrorF ("\nwinMultiWindowXMsgProcIOErrorHandler!\n\n");
+
+ /* Restart at the main entry point */
+ longjmp (g_jmpXMsgProcEntry, WIN_JMP_ERROR_IO);
+
+ return 0;
+}
+
+
+/*
+ * Catch RedirectError to detect other window manager running
+ */
+
+static int
+winRedirectErrorHandler (Display *pDisplay, XErrorEvent *pErr)
+{
+ redirectError = TRUE;
+ return 0;
+}
+
+
+/*
+ * Check if another window manager is running
+ */
+
+static Bool
+CheckAnotherWindowManager (Display *pDisplay, DWORD dwScreen)
+{
+ /*
+ Try to select the events which only one client at a time is allowed to select.
+ If this causes an error, another window manager is already running...
+ */
+ redirectError = FALSE;
+ XSetErrorHandler (winRedirectErrorHandler);
+ XSelectInput(pDisplay, RootWindow (pDisplay, dwScreen),
+ ResizeRedirectMask | SubstructureRedirectMask | ButtonPressMask);
+ XSync (pDisplay, 0);
+ XSetErrorHandler (winMultiWindowXMsgProcErrorHandler);
+
+ /*
+ Side effect: select the events we are actually interested in...
+ */
+ XSelectInput(pDisplay, RootWindow (pDisplay, dwScreen), SubstructureNotifyMask);
+ XSync (pDisplay, 0);
+ return redirectError;
+}
+
+/*
+ * Notify the MWM thread we're exiting and not to reconnect
+ */
+
+void
+winDeinitMultiWindowWM (void)
+{
+ winDebug ("winDeinitMultiWindowWM - Noting shutdown in progress\n");
+ g_shutdown = TRUE;
+}
+
+/* Windows window styles */
+#define HINT_NOFRAME (1l<<0)
+#define HINT_BORDER (1L<<1)
+#define HINT_SIZEBOX (1l<<2)
+#define HINT_CAPTION (1l<<3)
+/* These two are used on their own */
+#define HINT_MAX (1L<<0)
+#define HINT_MIN (1L<<1)
+
+static void
+winApplyHints (Display *pDisplay, Window iWindow, HWND hWnd, HWND *zstyle)
+{
+ static Atom windowState, motif_wm_hints, windowType;
+ static Atom hiddenState, fullscreenState, belowState, aboveState;
+ static Atom dockWindow;
+ static int generation;
+ Atom type, *pAtom = NULL;
+ int format;
+ unsigned long hint = 0, maxmin = 0, style, nitems = 0 , left = 0;
+ WindowPtr pWin = GetProp (hWnd, WIN_WINDOW_PROP);
+ MwmHints *mwm_hint = NULL;
+
+ if (!hWnd) return;
+ if (!IsWindow (hWnd)) return;
+
+ if (generation != serverGeneration) {
+ generation = serverGeneration;
+ windowState = XInternAtom(pDisplay, "_NET_WM_STATE", False);
+ motif_wm_hints = XInternAtom(pDisplay, "_MOTIF_WM_HINTS", False);
+ windowType = XInternAtom(pDisplay, "_NET_WM_WINDOW_TYPE", False);
+ hiddenState = XInternAtom(pDisplay, "_NET_WM_STATE_HIDDEN", False);
+ fullscreenState = XInternAtom(pDisplay, "_NET_WM_STATE_FULLSCREEN", False);
+ belowState = XInternAtom(pDisplay, "_NET_WM_STATE_BELOW", False);
+ aboveState = XInternAtom(pDisplay, "_NET_WM_STATE_ABOVE", False);
+ dockWindow = XInternAtom(pDisplay, "_NET_WM_WINDOW_TYPE_DOCK", False);
+ }
+
+ if (XGetWindowProperty(pDisplay, iWindow, windowState, 0L,
+ 1L, False, XA_ATOM, &type, &format,
+ &nitems, &left, (unsigned char **)&pAtom) == Success)
+ {
+ if (pAtom && nitems == 1)
+ {
+ if (*pAtom == hiddenState) maxmin |= HINT_MIN;
+ else if (*pAtom == fullscreenState) maxmin |= HINT_MAX;
+ if (*pAtom == belowState) *zstyle = HWND_BOTTOM;
+ else if (*pAtom == aboveState) *zstyle = HWND_TOPMOST;
+ }
+ if (pAtom) XFree(pAtom);
+ }
+
+ nitems = left = 0;
+ if (XGetWindowProperty(pDisplay, iWindow, motif_wm_hints, 0L,
+ PropMwmHintsElements, False, motif_wm_hints, &type, &format,
+ &nitems, &left, (unsigned char **)&mwm_hint) == Success)
+ {
+ if (mwm_hint && nitems == PropMwmHintsElements && (mwm_hint->flags & MwmHintsDecorations))
+ {
+ if (!mwm_hint->decorations) hint |= HINT_NOFRAME;
+ else if (!(mwm_hint->decorations & MwmDecorAll))
+ {
+ if (mwm_hint->decorations & MwmDecorBorder) hint |= HINT_BORDER;
+ if (mwm_hint->decorations & MwmDecorHandle) hint |= HINT_SIZEBOX;
+ if (mwm_hint->decorations & MwmDecorTitle) hint |= HINT_CAPTION;
+ }
+ }
+ if (mwm_hint) XFree(mwm_hint);
+ }
+
+ nitems = left = 0;
+ pAtom = NULL;
+ if (XGetWindowProperty(pDisplay, iWindow, windowType, 0L,
+ 1L, False, XA_ATOM, &type, &format,
+ &nitems, &left, (unsigned char **)&pAtom) == Success)
+ {
+ if (pAtom && nitems == 1)
+ {
+ if (*pAtom == dockWindow)
+ {
+ hint = (hint & ~HINT_NOFRAME) | HINT_SIZEBOX; /* Xming puts a sizebox on dock windows */
+ *zstyle = HWND_TOPMOST;
+ }
+ }
+ if (pAtom) XFree(pAtom);
+ }
+
+ /* Apply Styles, overriding hint settings from above */
+ style = winOverrideStyle((unsigned long)pWin);
+ if (style & STYLE_TOPMOST) *zstyle = HWND_TOPMOST;
+ else if (style & STYLE_MAXIMIZE) maxmin = (hint & ~HINT_MIN) | HINT_MAX;
+ else if (style & STYLE_MINIMIZE) maxmin = (hint & ~HINT_MAX) | HINT_MIN;
+ else if (style & STYLE_BOTTOM) *zstyle = HWND_BOTTOM;
+
+ if (maxmin & HINT_MAX) SendMessage(hWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
+ else if (maxmin & HINT_MIN) SendMessage(hWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
+
+ if (style & STYLE_NOTITLE)
+ hint = (hint & ~HINT_NOFRAME & ~HINT_BORDER & ~HINT_CAPTION) | HINT_SIZEBOX;
+ else if (style & STYLE_OUTLINE)
+ hint = (hint & ~HINT_NOFRAME & ~HINT_SIZEBOX & ~HINT_CAPTION) | HINT_BORDER;
+ else if (style & STYLE_NOFRAME)
+ hint = (hint & ~HINT_BORDER & ~HINT_CAPTION & ~HINT_SIZEBOX) | HINT_NOFRAME;
+
+ style = GetWindowLongPtr(hWnd, GWL_STYLE) & ~WS_CAPTION & ~WS_SIZEBOX; /* Just in case */
+ if (!style) return;
+ if (!hint) /* All on, but no resize of children is allowed */
+ style = style | WS_CAPTION | (GetParent(hWnd) ? 0 : WS_SIZEBOX);
+ else if (hint & HINT_NOFRAME); /* All off, so do nothing */
+ else style = style | ((hint & HINT_BORDER) ? WS_BORDER : 0) |
+ ((hint & HINT_SIZEBOX) ? (GetParent(hWnd) ? 0 : WS_SIZEBOX) : 0) |
+ ((hint & HINT_CAPTION) ? WS_CAPTION : 0);
+ SetWindowLongPtr (hWnd, GWL_STYLE, style);
+}
+
+void
+winUpdateWindowPosition (HWND hWnd, Bool reshape, HWND *zstyle)
+{
+ int iX, iY, iWidth, iHeight;
+ int iDx, iDy;
+ RECT rcNew;
+ WindowPtr pWin = GetProp (hWnd, WIN_WINDOW_PROP);
+ DrawablePtr pDraw = NULL;
+
+ if (!pWin) return;
+ pDraw = &pWin->drawable;
+ if (!pDraw) return;
+
+ /* Get the X and Y location of the X window */
+ 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;
+ iHeight = pWin->drawable.height;
+
+ /* Setup a rectangle with the X window position and size */
+ SetRect (&rcNew, iX, iY, iX + iWidth, iY + iHeight);
+
+ AdjustWindowRectEx (&rcNew, GetWindowLongPtr (hWnd, GWL_STYLE), FALSE, WS_EX_APPWINDOW);
+
+ /* Don't allow window decoration to disappear off to top-left as a result of this adjustment */
+ if (rcNew.left < GetSystemMetrics(SM_XVIRTUALSCREEN))
+ {
+ iDx = GetSystemMetrics(SM_XVIRTUALSCREEN) - rcNew.left;
+ rcNew.left += iDx;
+ rcNew.right += iDx;
+ }
+
+ if (rcNew.top < GetSystemMetrics(SM_YVIRTUALSCREEN))
+ {
+ iDy = GetSystemMetrics(SM_YVIRTUALSCREEN) - rcNew.top;
+ rcNew.top += iDy;
+ rcNew.bottom += iDy;
+ }
+
+ /* Position the Windows window */
+ SetWindowPos (hWnd, *zstyle, rcNew.left, rcNew.top,
+ rcNew.right - rcNew.left, rcNew.bottom - rcNew.top,
+ 0);
+
+ if (reshape)
+ {
+ winReshapeMultiWindow(pWin);
+ winUpdateRgnMultiWindow(pWin);
+ }
+}
diff --git a/xorg-server/hw/xwin/winprefs.h b/xorg-server/hw/xwin/winprefs.h index abfc7434e..ccd771d72 100644 --- a/xorg-server/hw/xwin/winprefs.h +++ b/xorg-server/hw/xwin/winprefs.h @@ -1,189 +1,192 @@ -#if !defined(WINPREFS_H) -#define WINPREFS_H -/* - * Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - * Copyright (C) Colin Harrison 2005-2008 - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name of the XFree86 Project - * shall not be used in advertising or otherwise to promote the sale, use - * or other dealings in this Software without prior written authorization - * from the XFree86 Project. - * - * Authors: Earle F. Philhower, III - * Colin Harrison - */ - -/* Need Bool */ -#include <X11/Xdefs.h> -/* Need TRUE */ -#include "misc.h" - -/* Need to know how long paths can be... */ -#include <limits.h> -/* Xwindows redefines PATH_MAX to at least 1024 */ -#include <X11/Xwindows.h> - -#ifndef NAME_MAX -#define NAME_MAX PATH_MAX -#endif -#define MENU_MAX 128 /* Maximum string length of a menu name or item */ -#define PARAM_MAX (4*PATH_MAX) /* Maximum length of a parameter to a MENU */ - - -/* Supported commands in a MENU {} statement */ -typedef enum MENUCOMMANDTYPE -{ - CMD_EXEC, /* /bin/sh -c the parameter */ - CMD_MENU, /* Display a popup menu named param */ - CMD_SEPARATOR, /* Menu separator */ - CMD_ALWAYSONTOP, /* Toggle always-on-top mode */ - CMD_RELOAD /* Reparse the .XWINRC file */ -} MENUCOMMANDTYPE; - -#define STYLE_NONE (0L) /* Dummy the first entry */ -#define STYLE_NOTITLE (1L) /* Force window style no titlebar */ -#define STYLE_OUTLINE (1L<<1) /* Force window style just thin-line border */ -#define STYLE_NOFRAME (1L<<2) /* Force window style no frame */ -#define STYLE_TOPMOST (1L<<3) /* Open a window always-on-top */ -#define STYLE_MAXIMIZE (1L<<4) /* Open a window maximized */ -#define STYLE_MINIMIZE (1L<<5) /* Open a window minimized */ -#define STYLE_BOTTOM (1L<<6) /* Open a window at the bottom of the Z order */ - -/* Where to place a system menu */ -typedef enum MENUPOSITION -{ - AT_START, /* Place menu at the top of the system menu */ - AT_END /* Put it at the bottom of the menu (default) */ -} MENUPOSITION; - -/* Menu item definitions */ -typedef struct MENUITEM -{ - char text[MENU_MAX+1]; /* To be displayed in menu */ - MENUCOMMANDTYPE cmd; /* What should it do? */ - char param[PARAM_MAX+1]; /* Any parameters? */ - unsigned long commandID; /* Windows WM_COMMAND ID assigned at runtime */ -} MENUITEM; - -/* A completely read in menu... */ -typedef struct MENUPARSED -{ - char menuName[MENU_MAX+1]; /* What's it called in the text? */ - MENUITEM *menuItem; /* Array of items */ - int menuItems; /* How big's the array? */ -} MENUPARSED; - -/* To map between a window and a system menu to add for it */ -typedef struct SYSMENUITEM -{ - char match[MENU_MAX+1]; /* String to look for to apply this sysmenu */ - char menuName[MENU_MAX+1]; /* Which menu to show? Used to set *menu */ - MENUPOSITION menuPos; /* Where to place it (ignored in root) */ -} SYSMENUITEM; - -/* To redefine icons for certain window types */ -typedef struct ICONITEM -{ - char match[MENU_MAX+1]; /* What string to search for? */ - char iconFile[PATH_MAX+NAME_MAX+2]; /* Icon location, WIN32 path */ - HICON hicon; /* LoadImage() result */ -} ICONITEM; - -/* To redefine styles for certain window types */ -typedef struct STYLEITEM -{ - char match[MENU_MAX+1]; /* What string to search for? */ - unsigned long type; /* What should it do? */ -} STYLEITEM; - -typedef struct WINPREFS -{ - /* Menu information */ - MENUPARSED *menu; /* Array of created menus */ - int menuItems; /* How big? */ - - /* Taskbar menu settings */ - char rootMenuName[MENU_MAX+1]; /* Menu for taskbar icon */ - - /* System menu addition menus */ - SYSMENUITEM *sysMenu; - int sysMenuItems; - - /* Which menu to add to unmatched windows? */ - char defaultSysMenuName[MENU_MAX+1]; - MENUPOSITION defaultSysMenuPos; /* Where to place it */ - - /* Icon information */ - char iconDirectory[PATH_MAX+1]; /* Where do the .icos lie? (Win32 path) */ - char defaultIconName[NAME_MAX+1]; /* Replacement for x.ico */ - char trayIconName[NAME_MAX+1]; /* Replacement for tray icon */ - - ICONITEM *icon; - int iconItems; - - STYLEITEM *style; - int styleItems; - - /* Silent exit flag */ - Bool fSilentExit; - -} WINPREFS; - - - - -/* Functions */ -void -LoadPreferences(void); - -void -SetupRootMenu (unsigned long hmenuRoot); - -void -SetupSysMenu (unsigned long hwndIn); - -void -HandleCustomWM_INITMENU(unsigned long hwndIn, - unsigned long hmenuIn); - -Bool -HandleCustomWM_COMMAND (unsigned long hwndIn, - int command); - -int -winIconIsOverride (unsigned hiconIn); - -HICON -winOverrideIcon (unsigned long longpWin); - -unsigned long -winOverrideStyle (unsigned long longpWin); - -unsigned long -winOverrideStyle (unsigned long longpWin); - -HICON -winTaskbarIcon(void); - -HICON -winOverrideDefaultIcon(int size); -#endif +#if !defined(WINPREFS_H)
+#define WINPREFS_H
+/*
+ * Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ * Copyright (C) Colin Harrison 2005-2008
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the XFree86 Project
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from the XFree86 Project.
+ *
+ * Authors: Earle F. Philhower, III
+ * Colin Harrison
+ */
+
+/* Need Bool */
+#include <X11/Xdefs.h>
+/* Need TRUE */
+#include "misc.h"
+
+/* Need to know how long paths can be... */
+#include <limits.h>
+/* Xwindows redefines PATH_MAX to at least 1024 */
+#include <X11/Xwindows.h>
+
+#ifndef NAME_MAX
+#define NAME_MAX PATH_MAX
+#endif
+#define MENU_MAX 128 /* Maximum string length of a menu name or item */
+#define PARAM_MAX (4*PATH_MAX) /* Maximum length of a parameter to a MENU */
+
+
+/* Supported commands in a MENU {} statement */
+typedef enum MENUCOMMANDTYPE
+{
+ CMD_EXEC, /* /bin/sh -c the parameter */
+ CMD_MENU, /* Display a popup menu named param */
+ CMD_SEPARATOR, /* Menu separator */
+ CMD_ALWAYSONTOP, /* Toggle always-on-top mode */
+ CMD_RELOAD /* Reparse the .XWINRC file */
+} MENUCOMMANDTYPE;
+
+#define STYLE_NONE (0L) /* Dummy the first entry */
+#define STYLE_NOTITLE (1L) /* Force window style no titlebar */
+#define STYLE_OUTLINE (1L<<1) /* Force window style just thin-line border */
+#define STYLE_NOFRAME (1L<<2) /* Force window style no frame */
+#define STYLE_TOPMOST (1L<<3) /* Open a window always-on-top */
+#define STYLE_MAXIMIZE (1L<<4) /* Open a window maximized */
+#define STYLE_MINIMIZE (1L<<5) /* Open a window minimized */
+#define STYLE_BOTTOM (1L<<6) /* Open a window at the bottom of the Z order */
+
+/* Where to place a system menu */
+typedef enum MENUPOSITION
+{
+ AT_START, /* Place menu at the top of the system menu */
+ AT_END /* Put it at the bottom of the menu (default) */
+} MENUPOSITION;
+
+/* Menu item definitions */
+typedef struct MENUITEM
+{
+ char text[MENU_MAX+1]; /* To be displayed in menu */
+ MENUCOMMANDTYPE cmd; /* What should it do? */
+ char param[PARAM_MAX+1]; /* Any parameters? */
+ unsigned long commandID; /* Windows WM_COMMAND ID assigned at runtime */
+} MENUITEM;
+
+/* A completely read in menu... */
+typedef struct MENUPARSED
+{
+ char menuName[MENU_MAX+1]; /* What's it called in the text? */
+ MENUITEM *menuItem; /* Array of items */
+ int menuItems; /* How big's the array? */
+} MENUPARSED;
+
+/* To map between a window and a system menu to add for it */
+typedef struct SYSMENUITEM
+{
+ char match[MENU_MAX+1]; /* String to look for to apply this sysmenu */
+ char menuName[MENU_MAX+1]; /* Which menu to show? Used to set *menu */
+ MENUPOSITION menuPos; /* Where to place it (ignored in root) */
+} SYSMENUITEM;
+
+/* To redefine icons for certain window types */
+typedef struct ICONITEM
+{
+ char match[MENU_MAX+1]; /* What string to search for? */
+ char iconFile[PATH_MAX+NAME_MAX+2]; /* Icon location, WIN32 path */
+ HICON hicon; /* LoadImage() result */
+} ICONITEM;
+
+/* To redefine styles for certain window types */
+typedef struct STYLEITEM
+{
+ char match[MENU_MAX+1]; /* What string to search for? */
+ unsigned long type; /* What should it do? */
+} STYLEITEM;
+
+typedef struct WINPREFS
+{
+ /* Menu information */
+ MENUPARSED *menu; /* Array of created menus */
+ int menuItems; /* How big? */
+
+ /* Taskbar menu settings */
+ char rootMenuName[MENU_MAX+1]; /* Menu for taskbar icon */
+
+ /* System menu addition menus */
+ SYSMENUITEM *sysMenu;
+ int sysMenuItems;
+
+ /* Which menu to add to unmatched windows? */
+ char defaultSysMenuName[MENU_MAX+1];
+ MENUPOSITION defaultSysMenuPos; /* Where to place it */
+
+ /* Icon information */
+ char iconDirectory[PATH_MAX+1]; /* Where do the .icos lie? (Win32 path) */
+ char defaultIconName[NAME_MAX+1]; /* Replacement for x.ico */
+ char trayIconName[NAME_MAX+1]; /* Replacement for tray icon */
+
+ ICONITEM *icon;
+ int iconItems;
+
+ STYLEITEM *style;
+ int styleItems;
+
+ /* Force exit flag */
+ Bool fForceExit;
+
+ /* Silent exit flag */
+ Bool fSilentExit;
+
+} WINPREFS;
+
+
+
+
+/* Functions */
+void
+LoadPreferences(void);
+
+void
+SetupRootMenu (unsigned long hmenuRoot);
+
+void
+SetupSysMenu (unsigned long hwndIn);
+
+void
+HandleCustomWM_INITMENU(unsigned long hwndIn,
+ unsigned long hmenuIn);
+
+Bool
+HandleCustomWM_COMMAND (unsigned long hwndIn,
+ int command);
+
+int
+winIconIsOverride (unsigned hiconIn);
+
+HICON
+winOverrideIcon (unsigned long longpWin);
+
+unsigned long
+winOverrideStyle (unsigned long longpWin);
+
+unsigned long
+winOverrideStyle (unsigned long longpWin);
+
+HICON
+winTaskbarIcon(void);
+
+HICON
+winOverrideDefaultIcon(int size);
+#endif
diff --git a/xorg-server/hw/xwin/winprefsyacc.y b/xorg-server/hw/xwin/winprefsyacc.y index 14ac3cb7e..653a4ab25 100644 --- a/xorg-server/hw/xwin/winprefsyacc.y +++ b/xorg-server/hw/xwin/winprefsyacc.y @@ -1,432 +1,460 @@ -%{ -/* - * Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - * Copyright (C) Colin Harrison 2005-2008 - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Except as contained in this notice, the name of the XFree86 Project - * shall not be used in advertising or otherwise to promote the sale, use - * or other dealings in this Software without prior written authorization - * from the XFree86 Project. - * - * Authors: Earle F. Philhower, III - * Colin Harrison - */ -/* $XFree86: $ */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include "winprefs.h" -#include "winmsg.h" - -/* The following give better error messages in bison at the cost of a few KB */ -#define YYERROR_VERBOSE 1 - -/* YYLTYPE_IS_TRIVIAL and YYENABLE_NLS defined to suppress warnings */ -#define YYLTYPE_IS_TRIVIAL 1 -#define YYENABLE_NLS 0 - -/* The global pref settings */ -WINPREFS pref; - -/* The working menu */ -static MENUPARSED menu; - -/* Functions for parsing the tokens into out structure */ -/* Defined at the end section of this file */ - -static void SetIconDirectory (char *path); -static void SetDefaultIcon (char *fname); -static void SetRootMenu (char *menu); -static void SetDefaultSysMenu (char *menu, int pos); -static void SetTrayIcon (char *fname); - -static void OpenMenu(char *menuname); -static void AddMenuLine(char *name, MENUCOMMANDTYPE cmd, char *param); -static void CloseMenu(void); - -static void OpenIcons(void); -static void AddIconLine(char *matchstr, char *iconfile); -static void CloseIcons(void); - -static void OpenStyles(void); -static void AddStyleLine(char *matchstr, unsigned long style); -static void CloseStyles(void); - -static void OpenSysMenu(void); -static void AddSysMenuLine(char *matchstr, char *menuname, int pos); -static void CloseSysMenu(void); - -static int yyerror (char *s); - -extern char *yytext; -extern int yylex(void); - -#define YYMALLOC malloc -#define YYFREE free - -%} - -%union { - char *sVal; - unsigned long uVal; - int iVal; -} - -%token NEWLINE MENU LB RB ICONDIRECTORY DEFAULTICON ICONS STYLES -%token TOPMOST MAXIMIZE MINIMIZE BOTTOM NOTITLE OUTLINE NOFRAME DEFAULTSYSMENU -%token SYSMENU ROOTMENU SEPARATOR ATSTART ATEND EXEC ALWAYSONTOP DEBUGTOK -%token RELOAD TRAYICON SILENTEXIT - -%token <sVal> STRING -%type <uVal> group1 -%type <uVal> group2 -%type <uVal> stylecombo -%type <iVal> atspot - -%% - -input: /* empty */ - | input line - ; - -line: NEWLINE - | command - ; - - -newline_or_nada: - | NEWLINE newline_or_nada - ; - -command: defaulticon - | icondirectory - | menu - | icons - | styles - | sysmenu - | rootmenu - | defaultsysmenu - | debug - | trayicon - | silentexit - ; - -trayicon: TRAYICON STRING NEWLINE { SetTrayIcon($2); free($2); } - ; - -rootmenu: ROOTMENU STRING NEWLINE { SetRootMenu($2); free($2); } - ; - -defaultsysmenu: DEFAULTSYSMENU STRING atspot NEWLINE { SetDefaultSysMenu($2, $3); free($2); } - ; - -defaulticon: DEFAULTICON STRING NEWLINE { SetDefaultIcon($2); free($2); } - ; - -icondirectory: ICONDIRECTORY STRING NEWLINE { SetIconDirectory($2); free($2); } - ; - -menuline: SEPARATOR NEWLINE newline_or_nada { AddMenuLine("-", CMD_SEPARATOR, ""); } - | STRING ALWAYSONTOP NEWLINE newline_or_nada { AddMenuLine($1, CMD_ALWAYSONTOP, ""); free($1); } - | STRING EXEC STRING NEWLINE newline_or_nada { AddMenuLine($1, CMD_EXEC, $3); free($1); free($3); } - | STRING MENU STRING NEWLINE newline_or_nada { AddMenuLine($1, CMD_MENU, $3); free($1); free($3); } - | STRING RELOAD NEWLINE newline_or_nada { AddMenuLine($1, CMD_RELOAD, ""); free($1); } - ; - -menulist: menuline - | menuline menulist - ; - -menu: MENU STRING LB { OpenMenu($2); free($2); } newline_or_nada menulist RB {CloseMenu();} - ; - -iconline: STRING STRING NEWLINE newline_or_nada { AddIconLine($1, $2); free($1); free($2); } - ; - -iconlist: iconline - | iconline iconlist - ; - -icons: ICONS LB {OpenIcons();} newline_or_nada iconlist RB {CloseIcons();} - ; - -group1: TOPMOST { $$=STYLE_TOPMOST; } - | MAXIMIZE { $$=STYLE_MAXIMIZE; } - | MINIMIZE { $$=STYLE_MINIMIZE; } - | BOTTOM { $$=STYLE_BOTTOM; } - ; - -group2: NOTITLE { $$=STYLE_NOTITLE; } - | OUTLINE { $$=STYLE_OUTLINE; } - | NOFRAME { $$=STYLE_NOFRAME; } - ; - -stylecombo: group1 { $$=$1; } - | group2 { $$=$1; } - | group1 group2 { $$=$1|$2; } - | group2 group1 { $$=$1|$2; } - ; - -styleline: STRING stylecombo NEWLINE newline_or_nada { AddStyleLine($1, $2); free($1); } - ; - -stylelist: styleline - | styleline stylelist - ; - -styles: STYLES LB {OpenStyles();} newline_or_nada stylelist RB {CloseStyles();} - ; - -atspot: { $$=AT_END; } - | ATSTART { $$=AT_START; } - | ATEND { $$=AT_END; } - ; - -sysmenuline: STRING STRING atspot NEWLINE newline_or_nada { AddSysMenuLine($1, $2, $3); free($1); free($2); } - ; - -sysmenulist: sysmenuline - | sysmenuline sysmenulist - ; - -sysmenu: SYSMENU LB NEWLINE {OpenSysMenu();} newline_or_nada sysmenulist RB {CloseSysMenu();} - ; - -silentexit: SILENTEXIT NEWLINE { pref.fSilentExit = TRUE; } - ; - -debug: DEBUGTOK STRING NEWLINE { winDebug("LoadPreferences: %s\n", $2); free($2); } - ; - - -%% -/* - * Errors in parsing abort and print log messages - */ -static int -yyerror (char *s) -{ - extern int yylineno; /* Handled by flex internally */ - - ErrorF("LoadPreferences: %s line %d\n", s, yylineno); - return 1; -} - -/* Miscellaneous functions to store TOKENs into the structure */ -static void -SetIconDirectory (char *path) -{ - strncpy (pref.iconDirectory, path, PATH_MAX); - pref.iconDirectory[PATH_MAX] = 0; -} - -static void -SetDefaultIcon (char *fname) -{ - strncpy (pref.defaultIconName, fname, NAME_MAX); - pref.defaultIconName[NAME_MAX] = 0; -} - -static void -SetTrayIcon (char *fname) -{ - strncpy (pref.trayIconName, fname, NAME_MAX); - pref.trayIconName[NAME_MAX] = 0; -} - -static void -SetRootMenu (char *menu) -{ - strncpy (pref.rootMenuName, menu, MENU_MAX); - pref.rootMenuName[MENU_MAX] = 0; -} - -static void -SetDefaultSysMenu (char *menu, int pos) -{ - strncpy (pref.defaultSysMenuName, menu, MENU_MAX); - pref.defaultSysMenuName[MENU_MAX] = 0; - pref.defaultSysMenuPos = pos; -} - -static void -OpenMenu (char *menuname) -{ - if (menu.menuItem) free(menu.menuItem); - menu.menuItem = NULL; - strncpy(menu.menuName, menuname, MENU_MAX); - menu.menuName[MENU_MAX] = 0; - menu.menuItems = 0; -} - -static void -AddMenuLine (char *text, MENUCOMMANDTYPE cmd, char *param) -{ - if (menu.menuItem==NULL) - menu.menuItem = (MENUITEM*)malloc(sizeof(MENUITEM)); - else - menu.menuItem = (MENUITEM*) - realloc(menu.menuItem, sizeof(MENUITEM)*(menu.menuItems+1)); - - strncpy (menu.menuItem[menu.menuItems].text, text, MENU_MAX); - menu.menuItem[menu.menuItems].text[MENU_MAX] = 0; - - menu.menuItem[menu.menuItems].cmd = cmd; - - strncpy(menu.menuItem[menu.menuItems].param, param, PARAM_MAX); - menu.menuItem[menu.menuItems].param[PARAM_MAX] = 0; - - menu.menuItem[menu.menuItems].commandID = 0; - - menu.menuItems++; -} - -static void -CloseMenu (void) -{ - if (menu.menuItem==NULL || menu.menuItems==0) - { - ErrorF("LoadPreferences: Empty menu detected\n"); - return; - } - - if (pref.menuItems) - pref.menu = (MENUPARSED*) - realloc (pref.menu, (pref.menuItems+1)*sizeof(MENUPARSED)); - else - pref.menu = (MENUPARSED*)malloc (sizeof(MENUPARSED)); - - memcpy (pref.menu+pref.menuItems, &menu, sizeof(MENUPARSED)); - pref.menuItems++; - - memset (&menu, 0, sizeof(MENUPARSED)); -} - -static void -OpenIcons (void) -{ - if (pref.icon != NULL) { - winDebug("LoadPreferences: Redefining icon mappings\n"); - free(pref.icon); - pref.icon = NULL; - } - pref.iconItems = 0; -} - -static void -AddIconLine (char *matchstr, char *iconfile) -{ - if (pref.icon==NULL) - pref.icon = (ICONITEM*)malloc(sizeof(ICONITEM)); - else - pref.icon = (ICONITEM*) - realloc(pref.icon, sizeof(ICONITEM)*(pref.iconItems+1)); - - strncpy(pref.icon[pref.iconItems].match, matchstr, MENU_MAX); - pref.icon[pref.iconItems].match[MENU_MAX] = 0; - - strncpy(pref.icon[pref.iconItems].iconFile, iconfile, PATH_MAX+NAME_MAX+1); - pref.icon[pref.iconItems].iconFile[PATH_MAX+NAME_MAX+1] = 0; - - pref.icon[pref.iconItems].hicon = 0; - - pref.iconItems++; -} - -static void -CloseIcons (void) -{ -} - -static void -OpenStyles (void) -{ - if (pref.style != NULL) { - winDebug("LoadPreferences: Redefining window style\n"); - free(pref.style); - pref.style = NULL; - } - pref.styleItems = 0; -} - -static void -AddStyleLine (char *matchstr, unsigned long style) -{ - if (pref.style==NULL) - pref.style = (STYLEITEM*)malloc(sizeof(STYLEITEM)); - else - pref.style = (STYLEITEM*) - realloc(pref.style, sizeof(STYLEITEM)*(pref.styleItems+1)); - - strncpy(pref.style[pref.styleItems].match, matchstr, MENU_MAX); - pref.style[pref.styleItems].match[MENU_MAX] = 0; - - pref.style[pref.styleItems].type = style; - - pref.styleItems++; -} - -static void -CloseStyles (void) -{ -} - -static void -OpenSysMenu (void) -{ - if (pref.sysMenu != NULL) { - winDebug("LoadPreferences: Redefining system menu\n"); - free(pref.sysMenu); - pref.sysMenu = NULL; - } - pref.sysMenuItems = 0; -} - -static void -AddSysMenuLine (char *matchstr, char *menuname, int pos) -{ - if (pref.sysMenu==NULL) - pref.sysMenu = (SYSMENUITEM*)malloc(sizeof(SYSMENUITEM)); - else - pref.sysMenu = (SYSMENUITEM*) - realloc(pref.sysMenu, sizeof(SYSMENUITEM)*(pref.sysMenuItems+1)); - - strncpy (pref.sysMenu[pref.sysMenuItems].match, matchstr, MENU_MAX); - pref.sysMenu[pref.sysMenuItems].match[MENU_MAX] = 0; - - strncpy (pref.sysMenu[pref.sysMenuItems].menuName, menuname, MENU_MAX); - pref.sysMenu[pref.sysMenuItems].menuName[MENU_MAX] = 0; - - pref.sysMenu[pref.sysMenuItems].menuPos = pos; - - pref.sysMenuItems++; -} - -static void -CloseSysMenu (void) -{ -} - +%{
+/*
+ * Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ * Copyright (C) Colin Harrison 2005-2008
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the XFree86 Project
+ * shall not be used in advertising or otherwise to promote the sale, use
+ * or other dealings in this Software without prior written authorization
+ * from the XFree86 Project.
+ *
+ * Authors: Earle F. Philhower, III
+ * Colin Harrison
+ */
+/* $XFree86: $ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "winprefs.h"
+#include "winmsg.h"
+
+/* The following give better error messages in bison at the cost of a few KB */
+#define YYERROR_VERBOSE 1
+
+/* YYLTYPE_IS_TRIVIAL and YYENABLE_NLS defined to suppress warnings */
+#define YYLTYPE_IS_TRIVIAL 1
+#define YYENABLE_NLS 0
+
+/* The global pref settings */
+WINPREFS pref;
+
+/* The working menu */
+static MENUPARSED menu;
+
+/* Functions for parsing the tokens into out structure */
+/* Defined at the end section of this file */
+
+static void SetIconDirectory (char *path);
+static void SetDefaultIcon (char *fname);
+static void SetRootMenu (char *menu);
+static void SetDefaultSysMenu (char *menu, int pos);
+static void SetTrayIcon (char *fname);
+
+static void OpenMenu(char *menuname);
+static void AddMenuLine(char *name, MENUCOMMANDTYPE cmd, char *param);
+static void CloseMenu(void);
+
+static void OpenIcons(void);
+static void AddIconLine(char *matchstr, char *iconfile);
+static void CloseIcons(void);
+
+static void OpenStyles(void);
+static void AddStyleLine(char *matchstr, unsigned long style);
+static void CloseStyles(void);
+
+static void OpenSysMenu(void);
+static void AddSysMenuLine(char *matchstr, char *menuname, int pos);
+static void CloseSysMenu(void);
+
+static int yyerror (char *s);
+
+extern char *yytext;
+extern int yylex(void);
+
+#define YYMALLOC malloc
+#define YYFREE free
+
+%}
+
+%union {
+ char *sVal;
+ unsigned long uVal;
+ int iVal;
+}
+
+%token NEWLINE
+%token MENU
+%token LB
+%token RB
+%token ICONDIRECTORY
+%token DEFAULTICON
+%token ICONS
+%token STYLES
+%token TOPMOST
+%token MAXIMIZE
+%token MINIMIZE
+%token BOTTOM
+%token NOTITLE
+%token OUTLINE
+%token NOFRAME
+%token DEFAULTSYSMENU
+%token SYSMENU
+%token ROOTMENU
+%token SEPARATOR
+%token ATSTART
+%token ATEND
+%token EXEC
+%token ALWAYSONTOP
+%token DEBUGTOK
+%token RELOAD
+%token TRAYICON
+%token FORCEEXIT
+%token SILENTEXIT
+
+%token <sVal> STRING
+%type <uVal> group1
+%type <uVal> group2
+%type <uVal> stylecombo
+%type <iVal> atspot
+
+%%
+
+input: /* empty */
+ | input line
+ ;
+
+line: NEWLINE
+ | command
+ ;
+
+
+newline_or_nada:
+ | NEWLINE newline_or_nada
+ ;
+
+command: defaulticon
+ | icondirectory
+ | menu
+ | icons
+ | styles
+ | sysmenu
+ | rootmenu
+ | defaultsysmenu
+ | debug
+ | trayicon
+ | forceexit
+ | silentexit
+ ;
+
+trayicon: TRAYICON STRING NEWLINE { SetTrayIcon($2); free($2); }
+ ;
+
+rootmenu: ROOTMENU STRING NEWLINE { SetRootMenu($2); free($2); }
+ ;
+
+defaultsysmenu: DEFAULTSYSMENU STRING atspot NEWLINE { SetDefaultSysMenu($2, $3); free($2); }
+ ;
+
+defaulticon: DEFAULTICON STRING NEWLINE { SetDefaultIcon($2); free($2); }
+ ;
+
+icondirectory: ICONDIRECTORY STRING NEWLINE { SetIconDirectory($2); free($2); }
+ ;
+
+menuline: SEPARATOR NEWLINE newline_or_nada { AddMenuLine("-", CMD_SEPARATOR, ""); }
+ | STRING ALWAYSONTOP NEWLINE newline_or_nada { AddMenuLine($1, CMD_ALWAYSONTOP, ""); free($1); }
+ | STRING EXEC STRING NEWLINE newline_or_nada { AddMenuLine($1, CMD_EXEC, $3); free($1); free($3); }
+ | STRING MENU STRING NEWLINE newline_or_nada { AddMenuLine($1, CMD_MENU, $3); free($1); free($3); }
+ | STRING RELOAD NEWLINE newline_or_nada { AddMenuLine($1, CMD_RELOAD, ""); free($1); }
+ ;
+
+menulist: menuline
+ | menuline menulist
+ ;
+
+menu: MENU STRING LB { OpenMenu($2); free($2); } newline_or_nada menulist RB {CloseMenu();}
+ ;
+
+iconline: STRING STRING NEWLINE newline_or_nada { AddIconLine($1, $2); free($1); free($2); }
+ ;
+
+iconlist: iconline
+ | iconline iconlist
+ ;
+
+icons: ICONS LB {OpenIcons();} newline_or_nada iconlist RB {CloseIcons();}
+ ;
+
+group1: TOPMOST { $$=STYLE_TOPMOST; }
+ | MAXIMIZE { $$=STYLE_MAXIMIZE; }
+ | MINIMIZE { $$=STYLE_MINIMIZE; }
+ | BOTTOM { $$=STYLE_BOTTOM; }
+ ;
+
+group2: NOTITLE { $$=STYLE_NOTITLE; }
+ | OUTLINE { $$=STYLE_OUTLINE; }
+ | NOFRAME { $$=STYLE_NOFRAME; }
+ ;
+
+stylecombo: group1 { $$=$1; }
+ | group2 { $$=$1; }
+ | group1 group2 { $$=$1|$2; }
+ | group2 group1 { $$=$1|$2; }
+ ;
+
+styleline: STRING stylecombo NEWLINE newline_or_nada { AddStyleLine($1, $2); free($1); }
+ ;
+
+stylelist: styleline
+ | styleline stylelist
+ ;
+
+styles: STYLES LB {OpenStyles();} newline_or_nada stylelist RB {CloseStyles();}
+ ;
+
+atspot: { $$=AT_END; }
+ | ATSTART { $$=AT_START; }
+ | ATEND { $$=AT_END; }
+ ;
+
+sysmenuline: STRING STRING atspot NEWLINE newline_or_nada { AddSysMenuLine($1, $2, $3); free($1); free($2); }
+ ;
+
+sysmenulist: sysmenuline
+ | sysmenuline sysmenulist
+ ;
+
+sysmenu: SYSMENU LB NEWLINE {OpenSysMenu();} newline_or_nada sysmenulist RB {CloseSysMenu();}
+ ;
+
+forceexit: FORCEEXIT NEWLINE { pref.fForceExit = TRUE; }
+ ;
+
+silentexit: SILENTEXIT NEWLINE { pref.fSilentExit = TRUE; }
+ ;
+
+debug: DEBUGTOK STRING NEWLINE { winDebug("LoadPreferences: %s\n", $2); free($2); }
+ ;
+
+
+%%
+/*
+ * Errors in parsing abort and print log messages
+ */
+static int
+yyerror (char *s)
+{
+ extern int yylineno; /* Handled by flex internally */
+
+ ErrorF("LoadPreferences: %s line %d\n", s, yylineno);
+ return 1;
+}
+
+/* Miscellaneous functions to store TOKENs into the structure */
+static void
+SetIconDirectory (char *path)
+{
+ strncpy (pref.iconDirectory, path, PATH_MAX);
+ pref.iconDirectory[PATH_MAX] = 0;
+}
+
+static void
+SetDefaultIcon (char *fname)
+{
+ strncpy (pref.defaultIconName, fname, NAME_MAX);
+ pref.defaultIconName[NAME_MAX] = 0;
+}
+
+static void
+SetTrayIcon (char *fname)
+{
+ strncpy (pref.trayIconName, fname, NAME_MAX);
+ pref.trayIconName[NAME_MAX] = 0;
+}
+
+static void
+SetRootMenu (char *menu)
+{
+ strncpy (pref.rootMenuName, menu, MENU_MAX);
+ pref.rootMenuName[MENU_MAX] = 0;
+}
+
+static void
+SetDefaultSysMenu (char *menu, int pos)
+{
+ strncpy (pref.defaultSysMenuName, menu, MENU_MAX);
+ pref.defaultSysMenuName[MENU_MAX] = 0;
+ pref.defaultSysMenuPos = pos;
+}
+
+static void
+OpenMenu (char *menuname)
+{
+ if (menu.menuItem) free(menu.menuItem);
+ menu.menuItem = NULL;
+ strncpy(menu.menuName, menuname, MENU_MAX);
+ menu.menuName[MENU_MAX] = 0;
+ menu.menuItems = 0;
+}
+
+static void
+AddMenuLine (char *text, MENUCOMMANDTYPE cmd, char *param)
+{
+ if (menu.menuItem==NULL)
+ menu.menuItem = (MENUITEM*)malloc(sizeof(MENUITEM));
+ else
+ menu.menuItem = (MENUITEM*)
+ realloc(menu.menuItem, sizeof(MENUITEM)*(menu.menuItems+1));
+
+ strncpy (menu.menuItem[menu.menuItems].text, text, MENU_MAX);
+ menu.menuItem[menu.menuItems].text[MENU_MAX] = 0;
+
+ menu.menuItem[menu.menuItems].cmd = cmd;
+
+ strncpy(menu.menuItem[menu.menuItems].param, param, PARAM_MAX);
+ menu.menuItem[menu.menuItems].param[PARAM_MAX] = 0;
+
+ menu.menuItem[menu.menuItems].commandID = 0;
+
+ menu.menuItems++;
+}
+
+static void
+CloseMenu (void)
+{
+ if (menu.menuItem==NULL || menu.menuItems==0)
+ {
+ ErrorF("LoadPreferences: Empty menu detected\n");
+ return;
+ }
+
+ if (pref.menuItems)
+ pref.menu = (MENUPARSED*)
+ realloc (pref.menu, (pref.menuItems+1)*sizeof(MENUPARSED));
+ else
+ pref.menu = (MENUPARSED*)malloc (sizeof(MENUPARSED));
+
+ memcpy (pref.menu+pref.menuItems, &menu, sizeof(MENUPARSED));
+ pref.menuItems++;
+
+ memset (&menu, 0, sizeof(MENUPARSED));
+}
+
+static void
+OpenIcons (void)
+{
+ if (pref.icon != NULL) {
+ winDebug("LoadPreferences: Redefining icon mappings\n");
+ free(pref.icon);
+ pref.icon = NULL;
+ }
+ pref.iconItems = 0;
+}
+
+static void
+AddIconLine (char *matchstr, char *iconfile)
+{
+ if (pref.icon==NULL)
+ pref.icon = (ICONITEM*)malloc(sizeof(ICONITEM));
+ else
+ pref.icon = (ICONITEM*)
+ realloc(pref.icon, sizeof(ICONITEM)*(pref.iconItems+1));
+
+ strncpy(pref.icon[pref.iconItems].match, matchstr, MENU_MAX);
+ pref.icon[pref.iconItems].match[MENU_MAX] = 0;
+
+ strncpy(pref.icon[pref.iconItems].iconFile, iconfile, PATH_MAX+NAME_MAX+1);
+ pref.icon[pref.iconItems].iconFile[PATH_MAX+NAME_MAX+1] = 0;
+
+ pref.icon[pref.iconItems].hicon = 0;
+
+ pref.iconItems++;
+}
+
+static void
+CloseIcons (void)
+{
+}
+
+static void
+OpenStyles (void)
+{
+ if (pref.style != NULL) {
+ winDebug("LoadPreferences: Redefining window style\n");
+ free(pref.style);
+ pref.style = NULL;
+ }
+ pref.styleItems = 0;
+}
+
+static void
+AddStyleLine (char *matchstr, unsigned long style)
+{
+ if (pref.style==NULL)
+ pref.style = (STYLEITEM*)malloc(sizeof(STYLEITEM));
+ else
+ pref.style = (STYLEITEM*)
+ realloc(pref.style, sizeof(STYLEITEM)*(pref.styleItems+1));
+
+ strncpy(pref.style[pref.styleItems].match, matchstr, MENU_MAX);
+ pref.style[pref.styleItems].match[MENU_MAX] = 0;
+
+ pref.style[pref.styleItems].type = style;
+
+ pref.styleItems++;
+}
+
+static void
+CloseStyles (void)
+{
+}
+
+static void
+OpenSysMenu (void)
+{
+ if (pref.sysMenu != NULL) {
+ winDebug("LoadPreferences: Redefining system menu\n");
+ free(pref.sysMenu);
+ pref.sysMenu = NULL;
+ }
+ pref.sysMenuItems = 0;
+}
+
+static void
+AddSysMenuLine (char *matchstr, char *menuname, int pos)
+{
+ if (pref.sysMenu==NULL)
+ pref.sysMenu = (SYSMENUITEM*)malloc(sizeof(SYSMENUITEM));
+ else
+ pref.sysMenu = (SYSMENUITEM*)
+ realloc(pref.sysMenu, sizeof(SYSMENUITEM)*(pref.sysMenuItems+1));
+
+ strncpy (pref.sysMenu[pref.sysMenuItems].match, matchstr, MENU_MAX);
+ pref.sysMenu[pref.sysMenuItems].match[MENU_MAX] = 0;
+
+ strncpy (pref.sysMenu[pref.sysMenuItems].menuName, menuname, MENU_MAX);
+ pref.sysMenu[pref.sysMenuItems].menuName[MENU_MAX] = 0;
+
+ pref.sysMenu[pref.sysMenuItems].menuPos = pos;
+
+ pref.sysMenuItems++;
+}
+
+static void
+CloseSysMenu (void)
+{
+}
+
diff --git a/xorg-server/hw/xwin/winprocarg.c b/xorg-server/hw/xwin/winprocarg.c index 995ed031e..8b8af966e 100644 --- a/xorg-server/hw/xwin/winprocarg.c +++ b/xorg-server/hw/xwin/winprocarg.c @@ -1,1541 +1,1539 @@ -/* - -Copyright 1993, 1998 The Open Group -Copyright (C) Colin Harrison 2005-2008 - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall -not be used in advertising or otherwise to promote the sale, use or -other dealings in this Software without prior written authorization -from The Open Group. - -*/ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#ifdef XVENDORNAME -#define VENDOR_STRING XVENDORNAME -#define VENDOR_CONTACT BUILDERADDR -#endif -#include <../xfree86/common/xorgVersion.h> -#include "win.h" -#include "winconfig.h" -#include "winprefs.h" -#include "winmsg.h" -#define COMPILE_MULTIMON_STUBS -#include <multimon.h> -/* - * References to external symbols - */ - -extern int g_iNumScreens; -extern winScreenInfo g_ScreenInfo[]; -extern int g_iLastScreen; -extern Bool g_fInitializedDefaultScreens; -#ifdef XWIN_CLIPBOARD -extern Bool g_fUnicodeClipboard; -extern Bool g_fClipboard; -#endif -extern int g_iLogVerbose; -extern char * g_pszLogFile; -#ifdef RELOCATE_PROJECTROOT -extern Bool g_fLogFileChanged; -#endif -extern Bool g_fXdmcpEnabled; -extern Bool g_fAuthEnabled; -extern char * g_pszCommandLine; -extern Bool g_fKeyboardHookLL; -extern Bool g_fNoHelpMessageBox; -extern Bool g_fSoftwareCursor; -extern Bool g_fSilentDupError; - -/* globals required by callback function for monitor information */ -struct GetMonitorInfoData { - int requestedMonitor; - int monitorNum; - Bool bUserSpecifiedMonitor; - Bool bMonitorSpecifiedExists; - int monitorOffsetX; - int monitorOffsetY; - int monitorHeight; - int monitorWidth; -}; - -wBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data); - -static Bool QueryMonitor(int index, struct GetMonitorInfoData *data) -{ - /* prepare data */ - if (data == NULL) - return FALSE; - memset(data, 0, sizeof(*data)); - data->requestedMonitor = index; - - /* query information */ - xEnumDisplayMonitors(NULL, NULL, getMonitorInfo, (LPARAM) data); - - return TRUE; -} - -/* - * Function prototypes - */ - -void -winLogCommandLine (int argc, char *argv[]); - -void -winLogVersionInfo (void); - -#ifdef DDXOSVERRORF -void OsVendorVErrorF (const char *pszFormat, va_list va_args); -#endif - -void -winInitializeDefaultScreens (void); - -/* - * Process arguments on the command line - */ - -void -winInitializeDefaultScreens (void) -{ - int i; - DWORD dwWidth, dwHeight; - - /* Bail out early if default screens have already been initialized */ - if (g_fInitializedDefaultScreens) - return; - - /* Zero the memory used for storing the screen info */ - ZeroMemory (g_ScreenInfo, MAXSCREENS * sizeof (winScreenInfo)); - - /* Get default width and height */ - /* - * NOTE: These defaults will cause the window to cover only - * the primary monitor in the case that we have multiple monitors. - */ - dwWidth = GetSystemMetrics (SM_CXSCREEN); - dwHeight = GetSystemMetrics (SM_CYSCREEN); - - winDebug ("winInitializeDefaultScreens - w %d h %d\n", - (int) dwWidth, (int) dwHeight); - - /* Set a default DPI, if no parameter was passed */ - if (monitorResolution == 0) - monitorResolution = WIN_DEFAULT_DPI; - - for (i = 0; i < MAXSCREENS; ++i) - { - g_ScreenInfo[i].dwScreen = i; - g_ScreenInfo[i].dwWidth = dwWidth; - g_ScreenInfo[i].dwHeight = dwHeight; - g_ScreenInfo[i].dwUserWidth = dwWidth; - g_ScreenInfo[i].dwUserHeight = dwHeight; - g_ScreenInfo[i].fUserGaveHeightAndWidth - = WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH; - g_ScreenInfo[i].fUserGavePosition = FALSE; - g_ScreenInfo[i].dwBPP = WIN_DEFAULT_BPP; - g_ScreenInfo[i].dwClipUpdatesNBoxes = WIN_DEFAULT_CLIP_UPDATES_NBOXES; -#ifdef XWIN_EMULATEPSEUDO - g_ScreenInfo[i].fEmulatePseudo = WIN_DEFAULT_EMULATE_PSEUDO; -#endif - g_ScreenInfo[i].dwRefreshRate = WIN_DEFAULT_REFRESH; - g_ScreenInfo[i].pfb = NULL; - g_ScreenInfo[i].fFullScreen = FALSE; - g_ScreenInfo[i].fDecoration = TRUE; -#ifdef XWIN_MULTIWINDOWEXTWM - g_ScreenInfo[i].fMWExtWM = FALSE; - g_ScreenInfo[i].fInternalWM = FALSE; -#endif - g_ScreenInfo[i].fRootless = FALSE; -#ifdef XWIN_MULTIWINDOW - g_ScreenInfo[i].fMultiWindow = FALSE; -#endif -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - g_ScreenInfo[i].fMultiMonitorOverride = FALSE; -#endif - g_ScreenInfo[i].fMultipleMonitors = FALSE; - g_ScreenInfo[i].fLessPointer = FALSE; - g_ScreenInfo[i].fScrollbars = FALSE; - g_ScreenInfo[i].fNoTrayIcon = FALSE; - g_ScreenInfo[i].iE3BTimeout = WIN_E3B_OFF; - g_ScreenInfo[i].dwWidth_mm = (dwWidth / WIN_DEFAULT_DPI) - * 25.4; - g_ScreenInfo[i].dwHeight_mm = (dwHeight / WIN_DEFAULT_DPI) - * 25.4; - g_ScreenInfo[i].fUseWinKillKey = WIN_DEFAULT_WIN_KILL; - g_ScreenInfo[i].fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL; - g_ScreenInfo[i].fIgnoreInput = FALSE; - g_ScreenInfo[i].fExplicitScreen = FALSE; - } - - /* Signal that the default screens have been initialized */ - g_fInitializedDefaultScreens = TRUE; - - winDebug ("winInitializeDefaultScreens - Returning\n"); -} - -/* See Porting Layer Definition - p. 57 */ -/* - * INPUT - * argv: pointer to an array of null-terminated strings, one for - * each token in the X Server command line; the first token - * is 'XWin.exe', or similar. - * argc: a count of the number of tokens stored in argv. - * i: a zero-based index into argv indicating the current token being - * processed. - * - * OUTPUT - * return: return the number of tokens processed correctly. - * - * NOTE - * When looking for n tokens, check that i + n is less than argc. Or, - * you may check if i is greater than or equal to argc, in which case - * you should display the UseMsg () and return 0. - */ - -/* Check if enough arguments are given for the option */ -#define CHECK_ARGS(count) if (i + count >= argc) { UseMsg (); return 0; } - -/* Compare the current option with the string. */ -#define IS_OPTION(name) (strcmp (argv[i], name) == 0) - -int -ddxProcessArgument (int argc, char *argv[], int i) -{ - static Bool s_fBeenHere = FALSE; - - /* Initialize once */ - if (!s_fBeenHere) - { -#ifdef DDXOSVERRORF - /* - * This initialises our hook into VErrorF () for catching log messages - * that are generated before OsInit () is called. - */ - OsVendorVErrorFProc = OsVendorVErrorF; -#endif - - s_fBeenHere = TRUE; - - /* Initialize only if option is not -help */ - if (!IS_OPTION("-help") && !IS_OPTION("-h") && !IS_OPTION("--help") && - !IS_OPTION("-version") && !IS_OPTION("--version")) - { - - /* Log the version information */ - winLogVersionInfo (); - - /* Log the command line */ - winLogCommandLine (argc, argv); - - /* - * Initialize default screen settings. We have to do this before - * OsVendorInit () gets called, otherwise we will overwrite - * settings changed by parameters such as -fullscreen, etc. - */ - winDebug ("ddxProcessArgument - Initializing default " - "screens\n"); - winInitializeDefaultScreens (); - } - } - - winDebug ("ddxProcessArgument - arg: %s\n", argv[i]); - - /* - * Look for the '-help' and similar options - */ - if (IS_OPTION ("-help") || IS_OPTION("-h") || IS_OPTION("--help")) - { - /* Reset logfile. We don't need that helpmessage in the logfile */ - g_pszLogFile = NULL; - g_fNoHelpMessageBox = TRUE; - UseMsg(); - exit (0); - return 1; - } - - if (IS_OPTION ("-version") || IS_OPTION("--version")) - { - /* Reset logfile. We don't need that versioninfo in the logfile */ - g_pszLogFile = NULL; - winLogVersionInfo (); - exit (0); - return 1; - } - - /* - * Look for the '-screen scr_num [width height]' argument - */ - if (IS_OPTION ("-screen")) - { - int iArgsProcessed = 1; - int nScreenNum; - int iWidth, iHeight, iX, iY; - int iMonitor; - - winDebug ("ddxProcessArgument - screen - argc: %d i: %d\n", - argc, i); - - /* Display the usage message if the argument is malformed */ - if (i + 1 >= argc) - { - return 0; - } - - /* Grab screen number */ - nScreenNum = atoi (argv[i + 1]); - - /* Validate the specified screen number */ - if (nScreenNum < 0 || nScreenNum >= MAXSCREENS) - { - ErrorF ("ddxProcessArgument - screen - Invalid screen number %d\n", - nScreenNum); - UseMsg (); - return 0; - } - - /* look for @m where m is monitor number */ - if (i + 2 < argc - && 1 == sscanf(argv[i + 2], "@%d", (int *) &iMonitor)) - { - struct GetMonitorInfoData data; - if (!QueryMonitor(iMonitor, &data)) - { - ErrorF ("ddxProcessArgument - screen - " - "Querying monitors is not supported on NT4 and Win95\n"); - } else if (data.bMonitorSpecifiedExists == TRUE) - { - winDebug("ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n", iMonitor); - iArgsProcessed = 3; - g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE; - g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE; - g_ScreenInfo[nScreenNum].dwWidth = data.monitorWidth; - g_ScreenInfo[nScreenNum].dwHeight = data.monitorHeight; - g_ScreenInfo[nScreenNum].dwUserWidth = data.monitorWidth; - g_ScreenInfo[nScreenNum].dwUserHeight = data.monitorHeight; - g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX; - g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY; - } - else - { - /* monitor does not exist, error out */ - ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n", - iMonitor); - UseMsg (); - exit (0); - return 0; - } - } - - /* Look for 'WxD' or 'W D' */ - else if (i + 2 < argc - && 2 == sscanf (argv[i + 2], "%dx%d", - (int *) &iWidth, - (int *) &iHeight)) - { - winDebug ("ddxProcessArgument - screen - Found ``WxD'' arg\n"); - iArgsProcessed = 3; - g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE; - g_ScreenInfo[nScreenNum].dwWidth = iWidth; - g_ScreenInfo[nScreenNum].dwHeight = iHeight; - g_ScreenInfo[nScreenNum].dwUserWidth = iWidth; - g_ScreenInfo[nScreenNum].dwUserHeight = iHeight; - /* Look for WxD+X+Y */ - if (2 == sscanf (argv[i + 2], "%*dx%*d+%d+%d", - (int *) &iX, - (int *) &iY)) - { - winDebug("ddxProcessArgument - screen - Found ``X+Y'' arg\n"); - g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE; - g_ScreenInfo[nScreenNum].dwInitialX = iX; - g_ScreenInfo[nScreenNum].dwInitialY = iY; - - /* look for WxD+X+Y@m where m is monitor number. take X,Y to be offsets from monitor's root position */ - if (1 == sscanf (argv[i + 2], "%*dx%*d+%*d+%*d@%d", - (int *) &iMonitor)) - { - struct GetMonitorInfoData data; - if (!QueryMonitor(iMonitor, &data)) - { - ErrorF ("ddxProcessArgument - screen - " - "Querying monitors is not supported on NT4 and Win95\n"); - } else if (data.bMonitorSpecifiedExists == TRUE) - { - g_ScreenInfo[nScreenNum].dwInitialX += data.monitorOffsetX; - g_ScreenInfo[nScreenNum].dwInitialY += data.monitorOffsetY; - } - else - { - /* monitor does not exist, error out */ - ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n", - iMonitor); - UseMsg (); - exit (0); - return 0; - } - - } - } - - /* look for WxD@m where m is monitor number */ - else if (1 == sscanf(argv[i + 2], "%*dx%*d@%d", - (int *) &iMonitor)) - { - struct GetMonitorInfoData data; - if (!QueryMonitor(iMonitor, &data)) - { - ErrorF ("ddxProcessArgument - screen - " - "Querying monitors is not supported on NT4 and Win95\n"); - } else if (data.bMonitorSpecifiedExists == TRUE) - { - winDebug ("ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n", iMonitor); - g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE; - g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX; - g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY; - } - else - { - /* monitor does not exist, error out */ - ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n", - iMonitor); - UseMsg (); - exit (0); - return 0; - } - - } - } - else if (i + 3 < argc - && 1 == sscanf (argv[i + 2], "%d", - (int *) &iWidth) - && 1 == sscanf (argv[i + 3], "%d", - (int *) &iHeight)) - { - winDebug ("ddxProcessArgument - screen - Found ``W D'' arg\n"); - iArgsProcessed = 4; - g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE; - g_ScreenInfo[nScreenNum].dwWidth = iWidth; - g_ScreenInfo[nScreenNum].dwHeight = iHeight; - g_ScreenInfo[nScreenNum].dwUserWidth = iWidth; - g_ScreenInfo[nScreenNum].dwUserHeight = iHeight; - if (i + 5 < argc - && 1 == sscanf (argv[i + 4], "%d", - (int *) &iX) - && 1 == sscanf (argv[i + 5], "%d", - (int *) &iY)) - { - winDebug ("ddxProcessArgument - screen - Found ``X Y'' arg\n"); - iArgsProcessed = 6; - g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE; - g_ScreenInfo[nScreenNum].dwInitialX = iX; - g_ScreenInfo[nScreenNum].dwInitialY = iY; - } - } - else - { - ErrorF ("ddxProcessArgument - screen - Did not find size arg. " - "dwWidth: %d dwHeight: %d\n", - (int) g_ScreenInfo[nScreenNum].dwWidth, - (int) g_ScreenInfo[nScreenNum].dwHeight); - iArgsProcessed = 2; - g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE; - } - - /* Calculate the screen width and height in millimeters */ - if (g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth) - { - g_ScreenInfo[nScreenNum].dwWidth_mm - = (g_ScreenInfo[nScreenNum].dwWidth - / monitorResolution) * 25.4; - g_ScreenInfo[nScreenNum].dwHeight_mm - = (g_ScreenInfo[nScreenNum].dwHeight - / monitorResolution) * 25.4; - } - - /* Flag that this screen was explicity specified by the user */ - g_ScreenInfo[nScreenNum].fExplicitScreen = TRUE; - - /* - * Keep track of the last screen number seen, as parameters seen - * before a screen number apply to all screens, whereas parameters - * seen after a screen number apply to that screen number only. - */ - g_iLastScreen = nScreenNum; - - /* Keep a count of the number of screens */ - ++g_iNumScreens; - - return iArgsProcessed; - } - - /* - * Look for the '-engine n' argument - */ - if (IS_OPTION ("-engine")) - { - DWORD dwEngine = 0; - CARD8 c8OnBits = 0; - - /* Display the usage message if the argument is malformed */ - if (++i >= argc) - { - UseMsg (); - return 0; - } - - /* Grab the argument */ - dwEngine = atoi (argv[i]); - - /* Count the one bits in the engine argument */ - c8OnBits = winCountBits (dwEngine); - - /* Argument should only have a single bit on */ - if (c8OnBits != 1) - { - UseMsg (); - return 0; - } - - /* Is this parameter attached to a screen or global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].dwEnginePreferred = dwEngine; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].dwEnginePreferred = dwEngine; - } - - /* Indicate that we have processed the argument */ - return 2; - } - - /* - * Look for the '-fullscreen' argument - */ - if (IS_OPTION ("-fullscreen")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - if (!g_ScreenInfo[j].fMultiMonitorOverride) - g_ScreenInfo[j].fMultipleMonitors = FALSE; -#endif - g_ScreenInfo[j].fFullScreen = TRUE; - } - } - else - { - /* Parameter is for a single screen */ -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride) - g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE; -#endif - g_ScreenInfo[g_iLastScreen].fFullScreen = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-lesspointer' argument - */ - if (IS_OPTION ("-lesspointer")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fLessPointer = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fLessPointer = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-nodecoration' argument - */ - if (IS_OPTION ("-nodecoration")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - if (!g_ScreenInfo[j].fMultiMonitorOverride) - g_ScreenInfo[j].fMultipleMonitors = FALSE; -#endif - g_ScreenInfo[j].fDecoration = FALSE; - } - } - else - { - /* Parameter is for a single screen */ -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride) - g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE; -#endif - g_ScreenInfo[g_iLastScreen].fDecoration = FALSE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - -#ifdef XWIN_MULTIWINDOWEXTWM - /* - * Look for the '-mwextwm' argument - */ - if (IS_OPTION ("-mwextwm")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - if (!g_ScreenInfo[j].fMultiMonitorOverride) - g_ScreenInfo[j].fMultipleMonitors = TRUE; - g_ScreenInfo[j].fMWExtWM = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride) - g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE; - g_ScreenInfo[g_iLastScreen].fMWExtWM = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - /* - * Look for the '-internalwm' argument - */ - if (IS_OPTION ("-internalwm")) - { - /* 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++) - { - if (!g_ScreenInfo[j].fMultiMonitorOverride) - g_ScreenInfo[j].fMultipleMonitors = TRUE; - g_ScreenInfo[j].fMWExtWM = TRUE; - g_ScreenInfo[j].fInternalWM = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride) - g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE; - g_ScreenInfo[g_iLastScreen].fMWExtWM = TRUE; - g_ScreenInfo[g_iLastScreen].fInternalWM = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } -#endif - - /* - * Look for the '-rootless' argument - */ - if (IS_OPTION ("-rootless")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - if (!g_ScreenInfo[j].fMultiMonitorOverride) - g_ScreenInfo[j].fMultipleMonitors = FALSE; -#endif - g_ScreenInfo[j].fRootless = TRUE; - } - } - else - { - /* Parameter is for a single screen */ -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride) - g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE; -#endif - g_ScreenInfo[g_iLastScreen].fRootless = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - -#ifdef XWIN_MULTIWINDOW - /* - * Look for the '-multiwindow' argument - */ - if (IS_OPTION ("-multiwindow")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - if (!g_ScreenInfo[j].fMultiMonitorOverride) - g_ScreenInfo[j].fMultipleMonitors = TRUE; -#endif - g_ScreenInfo[j].fMultiWindow = TRUE; - } - } - else - { - /* Parameter is for a single screen */ -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride) - g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE; -#endif - g_ScreenInfo[g_iLastScreen].fMultiWindow = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } -#endif - - /* - * Look for the '-multiplemonitors' argument - */ - if (IS_OPTION ("-multiplemonitors") - || IS_OPTION ("-multimonitors")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - g_ScreenInfo[j].fMultiMonitorOverride = TRUE; -#endif - g_ScreenInfo[j].fMultipleMonitors = TRUE; - } - } - else - { - /* Parameter is for a single screen */ -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride = TRUE; -#endif - g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-nomultiplemonitors' argument - */ - if (IS_OPTION ("-nomultiplemonitors") - || IS_OPTION ("-nomultimonitors")) - { - /* 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++) - { -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - g_ScreenInfo[j].fMultiMonitorOverride = TRUE; -#endif - g_ScreenInfo[j].fMultipleMonitors = FALSE; - } - } - else - { - /* Parameter is for a single screen */ -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride = TRUE; -#endif - g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - - /* - * Look for the '-scrollbars' argument - */ - if (IS_OPTION ("-scrollbars")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fScrollbars = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fScrollbars = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - -#ifdef XWIN_CLIPBOARD - /* - * Look for the '-clipboard' argument - */ - if (IS_OPTION ("-clipboard")) - { - g_fClipboard = TRUE; - - /* Indicate that we have processed this argument */ - return 1; - } -#endif - - - /* - * Look for the '-ignoreinput' argument - */ - if (IS_OPTION ("-ignoreinput")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fIgnoreInput = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fIgnoreInput = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-emulate3buttons' argument - */ - if (IS_OPTION ("-emulate3buttons")) - { - int iArgsProcessed = 1; - int iE3BTimeout = WIN_DEFAULT_E3B_TIME; - - /* Grab the optional timeout value */ - if (i + 1 < argc - && 1 == sscanf (argv[i + 1], "%d", - &iE3BTimeout)) - { - /* Indicate that we have processed the next argument */ - iArgsProcessed++; - } - else - { - /* - * sscanf () won't modify iE3BTimeout if it doesn't find - * the specified format; however, I want to be explicit - * about setting the default timeout in such cases to - * prevent some programs (me) from getting confused. - */ - iE3BTimeout = WIN_DEFAULT_E3B_TIME; - } - - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].iE3BTimeout = iE3BTimeout; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].iE3BTimeout = iE3BTimeout; - } - - /* Indicate that we have processed this argument */ - return iArgsProcessed; - } - - /* - * Look for the '-depth n' argument - */ - if (IS_OPTION ("-depth")) - { - DWORD dwBPP = 0; - - /* Display the usage message if the argument is malformed */ - if (++i >= argc) - { - UseMsg (); - return 0; - } - - /* Grab the argument */ - dwBPP = atoi (argv[i]); - - /* Is this parameter attached to a screen or global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].dwBPP = dwBPP; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].dwBPP = dwBPP; - } - - /* Indicate that we have processed the argument */ - return 2; - } - - /* - * Look for the '-refresh n' argument - */ - if (IS_OPTION ("-refresh")) - { - DWORD dwRefreshRate = 0; - - /* Display the usage message if the argument is malformed */ - if (++i >= argc) - { - UseMsg (); - return 0; - } - - /* Grab the argument */ - dwRefreshRate = atoi (argv[i]); - - /* Is this parameter attached to a screen or global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].dwRefreshRate = dwRefreshRate; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].dwRefreshRate = dwRefreshRate; - } - - /* Indicate that we have processed the argument */ - return 2; - } - - /* - * Look for the '-clipupdates num_boxes' argument - */ - if (IS_OPTION ("-clipupdates")) - { - DWORD dwNumBoxes = 0; - - /* Display the usage message if the argument is malformed */ - if (++i >= argc) - { - UseMsg (); - return 0; - } - - /* Grab the argument */ - dwNumBoxes = atoi (argv[i]); - - /* Is this parameter attached to a screen or global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].dwClipUpdatesNBoxes = dwNumBoxes; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].dwClipUpdatesNBoxes = dwNumBoxes; - } - - /* Indicate that we have processed the argument */ - return 2; - } - -#ifdef XWIN_EMULATEPSEUDO - /* - * Look for the '-emulatepseudo' argument - */ - if (IS_OPTION ("-emulatepseudo")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fEmulatePseudo = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fEmulatePseudo = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } -#endif - - /* - * Look for the '-nowinkill' argument - */ - if (IS_OPTION ("-nowinkill")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fUseWinKillKey = FALSE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fUseWinKillKey = FALSE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-winkill' argument - */ - if (IS_OPTION ("-winkill")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fUseWinKillKey = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fUseWinKillKey = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-nounixkill' argument - */ - if (IS_OPTION ("-nounixkill")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fUseUnixKillKey = FALSE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = FALSE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-unixkill' argument - */ - if (IS_OPTION ("-unixkill")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fUseUnixKillKey = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-notrayicon' argument - */ - if (IS_OPTION ("-notrayicon")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fNoTrayIcon = TRUE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fNoTrayIcon = TRUE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-trayicon' argument - */ - if (IS_OPTION ("-trayicon")) - { - /* Is this parameter attached to a screen or is it global? */ - if (-1 == g_iLastScreen) - { - int j; - - /* Parameter is for all screens */ - for (j = 0; j < MAXSCREENS; j++) - { - g_ScreenInfo[j].fNoTrayIcon = FALSE; - } - } - else - { - /* Parameter is for a single screen */ - g_ScreenInfo[g_iLastScreen].fNoTrayIcon = FALSE; - } - - /* Indicate that we have processed this argument */ - return 1; - } - - /* - * Look for the '-fp' argument - */ - if (IS_OPTION ("-fp")) - { - CHECK_ARGS (1); - g_cmdline.fontPath = argv[++i]; - return 0; /* Let DIX parse this again */ - } - - /* - * Look for the '-query' argument - */ - if (IS_OPTION ("-query")) - { - CHECK_ARGS (1); - g_fXdmcpEnabled = TRUE; - g_pszQueryHost = argv[++i]; - return 0; /* Let DIX parse this again */ - } - - /* - * Look for the '-auth' argument - */ - if (IS_OPTION ("-auth")) - { -#ifdef __MINGW32__ - HANDLE hFile; - char * pszFile; - CHECK_ARGS (1); - pszFile = argv[++i]; - hFile = CreateFile(pszFile,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); - if (hFile == INVALID_HANDLE_VALUE) - winMessageBoxF ("This authorization file for the -auth option could not be opened...\n" - "\"%s\"\n" - "You should use an \"Xauthority\" file in your HOME directory.\n" - "\nIgnoring and continuing.\n", - MB_ICONINFORMATION, - pszFile); -#endif - g_fAuthEnabled = TRUE; - return 0; /* Let DIX parse this again */ - } - - /* - * Look for the '-indirect' or '-broadcast' arguments - */ - if (IS_OPTION ("-indirect") - || IS_OPTION ("-broadcast")) - { - g_fXdmcpEnabled = TRUE; - return 0; /* Let DIX parse this again */ - } - - /* - * Look for the '-config' argument - */ - if (IS_OPTION ("-config") - || IS_OPTION ("-xf86config")) - { - CHECK_ARGS (1); -#ifdef XWIN_XF86CONFIG - g_cmdline.configFile = argv[++i]; -#else - winMessageBoxF ("The %s option is not supported in this " - "release.\n" - "Ignoring this option and continuing.\n", - MB_ICONINFORMATION, - argv[i]); -#endif - return 2; - } - - /* - * Look for the '-keyboard' argument - */ - if (IS_OPTION ("-keyboard")) - { -#ifdef XWIN_XF86CONFIG - CHECK_ARGS (1); - g_cmdline.keyboard = argv[++i]; -#else - winMessageBoxF ("The -keyboard option is not supported in this " - "release.\n" - "Ignoring this option and continuing.\n", - MB_ICONINFORMATION); -#endif - return 2; - } - - /* - * Look for the '-logfile' argument - */ - if (IS_OPTION ("-logfile")) - { - CHECK_ARGS (1); - g_pszLogFile = argv[++i]; -#ifdef RELOCATE_PROJECTROOT - g_fLogFileChanged = TRUE; -#endif - return 2; - } - - /* - * Look for the '-logverbose' argument - */ - if (IS_OPTION ("-logverbose")) - { - CHECK_ARGS (1); - g_iLogVerbose = atoi(argv[++i]); - return 2; - } - -#ifdef XWIN_CLIPBOARD - /* - * Look for the '-nounicodeclipboard' argument - */ - if (IS_OPTION ("-nounicodeclipboard")) - { - g_fUnicodeClipboard = FALSE; - /* Indicate that we have processed the argument */ - return 1; - } -#endif - - if (IS_OPTION ("-xkbrules")) - { - CHECK_ARGS (1); - g_cmdline.xkbRules = argv[++i]; - return 2; - } - if (IS_OPTION ("-xkbmodel")) - { - CHECK_ARGS (1); - g_cmdline.xkbModel = argv[++i]; - return 2; - } - if (IS_OPTION ("-xkblayout")) - { - CHECK_ARGS (1); - g_cmdline.xkbLayout = argv[++i]; - return 2; - } - if (IS_OPTION ("-xkbvariant")) - { - CHECK_ARGS (1); - g_cmdline.xkbVariant = argv[++i]; - return 2; - } - if (IS_OPTION ("-xkboptions")) - { - CHECK_ARGS (1); - g_cmdline.xkbOptions = argv[++i]; - return 2; - } - - if (IS_OPTION ("-keyhook")) - { - g_fKeyboardHookLL = TRUE; - return 1; - } - - if (IS_OPTION ("-nokeyhook")) - { - g_fKeyboardHookLL = FALSE; - return 1; - } - - if (IS_OPTION ("-swcursor")) - { - g_fSoftwareCursor = TRUE; - return 1; - } - - if (IS_OPTION ("-silent-dup-error")) - { - g_fSilentDupError = TRUE; - return 1; - } - return 0; -} - - -/* - * winLogCommandLine - Write entire command line to the log file - */ - -void -winLogCommandLine (int argc, char *argv[]) -{ - int i; - int iSize = 0; - int iCurrLen = 0; - -#define CHARS_PER_LINE 60 - - /* Bail if command line has already been logged */ - if (g_pszCommandLine) - return; - - /* Count how much memory is needed for concatenated command line */ - for (i = 0, iCurrLen = 0; i < argc; ++i) - if (argv[i]) - { - /* Adds two characters for lines that overflow */ - if ((strlen (argv[i]) < CHARS_PER_LINE - && iCurrLen + strlen (argv[i]) > CHARS_PER_LINE) - || strlen (argv[i]) > CHARS_PER_LINE) - { - iCurrLen = 0; - iSize += 2; - } - - /* Add space for item and trailing space */ - iSize += strlen (argv[i]) + 1; - - /* Update current line length */ - iCurrLen += strlen (argv[i]); - } - - /* Allocate memory for concatenated command line */ - g_pszCommandLine = malloc (iSize + 1); - if (!g_pszCommandLine) - FatalError ("winLogCommandLine - Could not allocate memory for " - "command line string. Exiting.\n"); - - /* Set first character to concatenated command line to null */ - g_pszCommandLine[0] = '\0'; - - /* Loop through all args */ - for (i = 0, iCurrLen = 0; i < argc; ++i) - { - /* Add a character for lines that overflow */ - if ((strlen (argv[i]) < CHARS_PER_LINE - && iCurrLen + strlen (argv[i]) > CHARS_PER_LINE) - || strlen (argv[i]) > CHARS_PER_LINE) - { - iCurrLen = 0; - - /* Add line break if it fits */ - strncat (g_pszCommandLine, "\n ", iSize - strlen (g_pszCommandLine)); - } - - strncat (g_pszCommandLine, argv[i], iSize - strlen (g_pszCommandLine)); - strncat (g_pszCommandLine, " ", iSize - strlen (g_pszCommandLine)); - - /* Save new line length */ - iCurrLen += strlen (argv[i]); - } - - winDebug ("XWin was started with the following command line:\n\n" - "%s\n\n", g_pszCommandLine); -} - - -/* - * winLogVersionInfo - Log Cygwin/X version information - */ - -void -winLogVersionInfo (void) -{ -#ifdef WINDBG - static Bool s_fBeenHere = FALSE; - - if (s_fBeenHere) - return; - s_fBeenHere = TRUE; - - winDebug ("Welcome to the VcXsrv X Server\n"); - winDebug ("Vendor: %s\n", VENDOR_STRING); - winDebug ("Release: %d.%d.%d.%d (%d)\n\n", XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, XORG_VERSION_SNAP, XORG_VERSION_CURRENT); - winDebug ("Contact: %s\n\n", VENDOR_CONTACT); -#endif -} -/* - * getMonitorInfo - callback function used to return information from the enumeration of monitors attached - */ - -wBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data) -{ - struct GetMonitorInfoData* data = (struct GetMonitorInfoData*)_data; - // only get data for monitor number specified in <data> - data->monitorNum++; - if (data->monitorNum == data->requestedMonitor) - { - data->bMonitorSpecifiedExists = TRUE; - data->monitorOffsetX = rect->left; - data->monitorOffsetY = rect->top; - data->monitorHeight = rect->bottom - rect->top; - data->monitorWidth = rect->right - rect->left; - return FALSE; - } - return TRUE; -} +/*
+
+Copyright 1993, 1998 The Open Group
+Copyright (C) Colin Harrison 2005-2008
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#ifdef XVENDORNAME
+#define VENDOR_STRING XVENDORNAME
+#define VENDOR_CONTACT BUILDERADDR
+#endif
+#include <../xfree86/common/xorgVersion.h>
+#include "win.h"
+#include "winconfig.h"
+#include "winprefs.h"
+#include "winmsg.h"
+#define COMPILE_MULTIMON_STUBS
+#include <multimon.h>
+/*
+ * References to external symbols
+ */
+
+extern int g_iNumScreens;
+extern winScreenInfo g_ScreenInfo[];
+extern int g_iLastScreen;
+extern Bool g_fInitializedDefaultScreens;
+#ifdef XWIN_CLIPBOARD
+extern Bool g_fUnicodeClipboard;
+extern Bool g_fClipboard;
+#endif
+extern int g_iLogVerbose;
+extern char * g_pszLogFile;
+#ifdef RELOCATE_PROJECTROOT
+extern Bool g_fLogFileChanged;
+#endif
+extern Bool g_fXdmcpEnabled;
+extern Bool g_fAuthEnabled;
+extern char * g_pszCommandLine;
+extern Bool g_fKeyboardHookLL;
+extern Bool g_fNoHelpMessageBox;
+extern Bool g_fSoftwareCursor;
+extern Bool g_fSilentDupError;
+
+/* globals required by callback function for monitor information */
+struct GetMonitorInfoData {
+ int requestedMonitor;
+ int monitorNum;
+ Bool bUserSpecifiedMonitor;
+ Bool bMonitorSpecifiedExists;
+ int monitorOffsetX;
+ int monitorOffsetY;
+ int monitorHeight;
+ int monitorWidth;
+};
+
+wBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data);
+
+static Bool QueryMonitor(int index, struct GetMonitorInfoData *data)
+{
+ /* prepare data */
+ if (data == NULL)
+ return FALSE;
+ memset(data, 0, sizeof(*data));
+ data->requestedMonitor = index;
+
+ /* query information */
+ xEnumDisplayMonitors(NULL, NULL, getMonitorInfo, (LPARAM) data);
+
+ return TRUE;
+}
+
+/*
+ * Function prototypes
+ */
+
+void
+winLogCommandLine (int argc, char *argv[]);
+
+void
+winLogVersionInfo (void);
+
+#ifdef DDXOSVERRORF
+void OsVendorVErrorF (const char *pszFormat, va_list va_args);
+#endif
+
+void
+winInitializeDefaultScreens (void);
+
+/*
+ * Process arguments on the command line
+ */
+
+void
+winInitializeDefaultScreens (void)
+{
+ int i;
+ DWORD dwWidth, dwHeight;
+
+ /* Bail out early if default screens have already been initialized */
+ if (g_fInitializedDefaultScreens)
+ return;
+
+ /* Zero the memory used for storing the screen info */
+ ZeroMemory (g_ScreenInfo, MAXSCREENS * sizeof (winScreenInfo));
+
+ /* Get default width and height */
+ /*
+ * NOTE: These defaults will cause the window to cover only
+ * the primary monitor in the case that we have multiple monitors.
+ */
+ dwWidth = GetSystemMetrics (SM_CXSCREEN);
+ dwHeight = GetSystemMetrics (SM_CYSCREEN);
+
+ winDebug ("winInitializeDefaultScreens - w %d h %d\n",
+ (int) dwWidth, (int) dwHeight);
+
+ /* Set a default DPI, if no parameter was passed */
+ if (monitorResolution == 0)
+ monitorResolution = WIN_DEFAULT_DPI;
+
+ for (i = 0; i < MAXSCREENS; ++i)
+ {
+ g_ScreenInfo[i].dwScreen = i;
+ g_ScreenInfo[i].dwWidth = dwWidth;
+ g_ScreenInfo[i].dwHeight = dwHeight;
+ g_ScreenInfo[i].dwUserWidth = dwWidth;
+ g_ScreenInfo[i].dwUserHeight = dwHeight;
+ g_ScreenInfo[i].fUserGaveHeightAndWidth
+ = WIN_DEFAULT_USER_GAVE_HEIGHT_AND_WIDTH;
+ g_ScreenInfo[i].fUserGavePosition = FALSE;
+ g_ScreenInfo[i].dwBPP = WIN_DEFAULT_BPP;
+ g_ScreenInfo[i].dwClipUpdatesNBoxes = WIN_DEFAULT_CLIP_UPDATES_NBOXES;
+#ifdef XWIN_EMULATEPSEUDO
+ g_ScreenInfo[i].fEmulatePseudo = WIN_DEFAULT_EMULATE_PSEUDO;
+#endif
+ g_ScreenInfo[i].dwRefreshRate = WIN_DEFAULT_REFRESH;
+ g_ScreenInfo[i].pfb = NULL;
+ g_ScreenInfo[i].fFullScreen = FALSE;
+ g_ScreenInfo[i].fDecoration = TRUE;
+#ifdef XWIN_MULTIWINDOWEXTWM
+ g_ScreenInfo[i].fMWExtWM = FALSE;
+ g_ScreenInfo[i].fInternalWM = FALSE;
+#endif
+ g_ScreenInfo[i].fRootless = FALSE;
+#ifdef XWIN_MULTIWINDOW
+ g_ScreenInfo[i].fMultiWindow = FALSE;
+#endif
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ g_ScreenInfo[i].fMultiMonitorOverride = FALSE;
+#endif
+ g_ScreenInfo[i].fMultipleMonitors = FALSE;
+ g_ScreenInfo[i].fLessPointer = FALSE;
+ g_ScreenInfo[i].fScrollbars = FALSE;
+ g_ScreenInfo[i].fNoTrayIcon = FALSE;
+ g_ScreenInfo[i].iE3BTimeout = WIN_E3B_OFF;
+ g_ScreenInfo[i].dwWidth_mm = (dwWidth / WIN_DEFAULT_DPI)
+ * 25.4;
+ g_ScreenInfo[i].dwHeight_mm = (dwHeight / WIN_DEFAULT_DPI)
+ * 25.4;
+ g_ScreenInfo[i].fUseWinKillKey = WIN_DEFAULT_WIN_KILL;
+ g_ScreenInfo[i].fUseUnixKillKey = WIN_DEFAULT_UNIX_KILL;
+ g_ScreenInfo[i].fIgnoreInput = FALSE;
+ g_ScreenInfo[i].fExplicitScreen = FALSE;
+ }
+
+ /* Signal that the default screens have been initialized */
+ g_fInitializedDefaultScreens = TRUE;
+
+ winDebug ("winInitializeDefaultScreens - Returning\n");
+}
+
+/* See Porting Layer Definition - p. 57 */
+/*
+ * INPUT
+ * argv: pointer to an array of null-terminated strings, one for
+ * each token in the X Server command line; the first token
+ * is 'XWin.exe', or similar.
+ * argc: a count of the number of tokens stored in argv.
+ * i: a zero-based index into argv indicating the current token being
+ * processed.
+ *
+ * OUTPUT
+ * return: return the number of tokens processed correctly.
+ *
+ * NOTE
+ * When looking for n tokens, check that i + n is less than argc. Or,
+ * you may check if i is greater than or equal to argc, in which case
+ * you should display the UseMsg () and return 0.
+ */
+
+/* Check if enough arguments are given for the option */
+#define CHECK_ARGS(count) if (i + count >= argc) { UseMsg (); return 0; }
+
+/* Compare the current option with the string. */
+#define IS_OPTION(name) (strcmp (argv[i], name) == 0)
+
+int
+ddxProcessArgument (int argc, char *argv[], int i)
+{
+ static Bool s_fBeenHere = FALSE;
+
+ /* Initialize once */
+ if (!s_fBeenHere)
+ {
+#ifdef DDXOSVERRORF
+ /*
+ * This initialises our hook into VErrorF () for catching log messages
+ * that are generated before OsInit () is called.
+ */
+ OsVendorVErrorFProc = OsVendorVErrorF;
+#endif
+
+ s_fBeenHere = TRUE;
+
+ /* Initialize only if option is not -help */
+ if (!IS_OPTION("-help") && !IS_OPTION("-h") && !IS_OPTION("--help") &&
+ !IS_OPTION("-version") && !IS_OPTION("--version"))
+ {
+
+ /* Log the version information */
+ winLogVersionInfo ();
+
+ /* Log the command line */
+ winLogCommandLine (argc, argv);
+
+ /*
+ * Initialize default screen settings. We have to do this before
+ * OsVendorInit () gets called, otherwise we will overwrite
+ * settings changed by parameters such as -fullscreen, etc.
+ */
+ winDebug ("ddxProcessArgument - Initializing default "
+ "screens\n");
+ winInitializeDefaultScreens ();
+ }
+ }
+
+ winDebug ("ddxProcessArgument - arg: %s\n", argv[i]);
+
+ /*
+ * Look for the '-help' and similar options
+ */
+ if (IS_OPTION ("-help") || IS_OPTION("-h") || IS_OPTION("--help"))
+ {
+ /* Reset logfile. We don't need that helpmessage in the logfile */
+ g_pszLogFile = NULL;
+ g_fNoHelpMessageBox = TRUE;
+ UseMsg();
+ exit (0);
+ return 1;
+ }
+
+ if (IS_OPTION ("-version") || IS_OPTION("--version"))
+ {
+ /* Reset logfile. We don't need that versioninfo in the logfile */
+ g_pszLogFile = NULL;
+ winLogVersionInfo ();
+ exit (0);
+ return 1;
+ }
+
+ /*
+ * Look for the '-screen scr_num [width height]' argument
+ */
+ if (IS_OPTION ("-screen"))
+ {
+ int iArgsProcessed = 1;
+ int nScreenNum;
+ int iWidth, iHeight, iX, iY;
+ int iMonitor;
+
+ winDebug ("ddxProcessArgument - screen - argc: %d i: %d\n",
+ argc, i);
+
+ /* Display the usage message if the argument is malformed */
+ if (i + 1 >= argc)
+ {
+ return 0;
+ }
+
+ /* Grab screen number */
+ nScreenNum = atoi (argv[i + 1]);
+
+ /* Validate the specified screen number */
+ if (nScreenNum < 0 || nScreenNum >= MAXSCREENS)
+ {
+ ErrorF ("ddxProcessArgument - screen - Invalid screen number %d\n",
+ nScreenNum);
+ UseMsg ();
+ return 0;
+ }
+
+ /* look for @m where m is monitor number */
+ if (i + 2 < argc
+ && 1 == sscanf(argv[i + 2], "@%d", (int *) &iMonitor))
+ {
+ struct GetMonitorInfoData data;
+ if (!QueryMonitor(iMonitor, &data))
+ {
+ ErrorF ("ddxProcessArgument - screen - "
+ "Querying monitors is not supported on NT4 and Win95\n");
+ } else if (data.bMonitorSpecifiedExists == TRUE)
+ {
+ winDebug("ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n", iMonitor);
+ iArgsProcessed = 3;
+ g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE;
+ g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
+ g_ScreenInfo[nScreenNum].dwWidth = data.monitorWidth;
+ g_ScreenInfo[nScreenNum].dwHeight = data.monitorHeight;
+ g_ScreenInfo[nScreenNum].dwUserWidth = data.monitorWidth;
+ g_ScreenInfo[nScreenNum].dwUserHeight = data.monitorHeight;
+ g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX;
+ g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY;
+ }
+ else
+ {
+ /* monitor does not exist, error out */
+ ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
+ iMonitor);
+ UseMsg ();
+ exit (0);
+ return 0;
+ }
+ }
+
+ /* Look for 'WxD' or 'W D' */
+ else if (i + 2 < argc
+ && 2 == sscanf (argv[i + 2], "%dx%d",
+ (int *) &iWidth,
+ (int *) &iHeight))
+ {
+ winDebug ("ddxProcessArgument - screen - Found ``WxD'' arg\n");
+ iArgsProcessed = 3;
+ g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE;
+ g_ScreenInfo[nScreenNum].dwWidth = iWidth;
+ g_ScreenInfo[nScreenNum].dwHeight = iHeight;
+ g_ScreenInfo[nScreenNum].dwUserWidth = iWidth;
+ g_ScreenInfo[nScreenNum].dwUserHeight = iHeight;
+ /* Look for WxD+X+Y */
+ if (2 == sscanf (argv[i + 2], "%*dx%*d+%d+%d",
+ (int *) &iX,
+ (int *) &iY))
+ {
+ winDebug("ddxProcessArgument - screen - Found ``X+Y'' arg\n");
+ g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
+ g_ScreenInfo[nScreenNum].dwInitialX = iX;
+ g_ScreenInfo[nScreenNum].dwInitialY = iY;
+
+ /* look for WxD+X+Y@m where m is monitor number. take X,Y to be offsets from monitor's root position */
+ if (1 == sscanf (argv[i + 2], "%*dx%*d+%*d+%*d@%d",
+ (int *) &iMonitor))
+ {
+ struct GetMonitorInfoData data;
+ if (!QueryMonitor(iMonitor, &data))
+ {
+ ErrorF ("ddxProcessArgument - screen - "
+ "Querying monitors is not supported on NT4 and Win95\n");
+ } else if (data.bMonitorSpecifiedExists == TRUE)
+ {
+ g_ScreenInfo[nScreenNum].dwInitialX += data.monitorOffsetX;
+ g_ScreenInfo[nScreenNum].dwInitialY += data.monitorOffsetY;
+ }
+ else
+ {
+ /* monitor does not exist, error out */
+ ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
+ iMonitor);
+ UseMsg ();
+ exit (0);
+ return 0;
+ }
+
+ }
+ }
+
+ /* look for WxD@m where m is monitor number */
+ else if (1 == sscanf(argv[i + 2], "%*dx%*d@%d",
+ (int *) &iMonitor))
+ {
+ struct GetMonitorInfoData data;
+ if (!QueryMonitor(iMonitor, &data))
+ {
+ ErrorF ("ddxProcessArgument - screen - "
+ "Querying monitors is not supported on NT4 and Win95\n");
+ } else if (data.bMonitorSpecifiedExists == TRUE)
+ {
+ winDebug ("ddxProcessArgument - screen - Found Valid ``@Monitor'' = %d arg\n", iMonitor);
+ g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
+ g_ScreenInfo[nScreenNum].dwInitialX = data.monitorOffsetX;
+ g_ScreenInfo[nScreenNum].dwInitialY = data.monitorOffsetY;
+ }
+ else
+ {
+ /* monitor does not exist, error out */
+ ErrorF ("ddxProcessArgument - screen - Invalid monitor number %d\n",
+ iMonitor);
+ UseMsg ();
+ exit (0);
+ return 0;
+ }
+
+ }
+ }
+ else if (i + 3 < argc
+ && 1 == sscanf (argv[i + 2], "%d",
+ (int *) &iWidth)
+ && 1 == sscanf (argv[i + 3], "%d",
+ (int *) &iHeight))
+ {
+ winDebug ("ddxProcessArgument - screen - Found ``W D'' arg\n");
+ iArgsProcessed = 4;
+ g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = TRUE;
+ g_ScreenInfo[nScreenNum].dwWidth = iWidth;
+ g_ScreenInfo[nScreenNum].dwHeight = iHeight;
+ g_ScreenInfo[nScreenNum].dwUserWidth = iWidth;
+ g_ScreenInfo[nScreenNum].dwUserHeight = iHeight;
+ if (i + 5 < argc
+ && 1 == sscanf (argv[i + 4], "%d",
+ (int *) &iX)
+ && 1 == sscanf (argv[i + 5], "%d",
+ (int *) &iY))
+ {
+ winDebug ("ddxProcessArgument - screen - Found ``X Y'' arg\n");
+ iArgsProcessed = 6;
+ g_ScreenInfo[nScreenNum].fUserGavePosition = TRUE;
+ g_ScreenInfo[nScreenNum].dwInitialX = iX;
+ g_ScreenInfo[nScreenNum].dwInitialY = iY;
+ }
+ }
+ else
+ {
+ ErrorF ("ddxProcessArgument - screen - Did not find size arg. "
+ "dwWidth: %d dwHeight: %d\n",
+ (int) g_ScreenInfo[nScreenNum].dwWidth,
+ (int) g_ScreenInfo[nScreenNum].dwHeight);
+ iArgsProcessed = 2;
+ g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth = FALSE;
+ }
+
+ /* Calculate the screen width and height in millimeters */
+ if (g_ScreenInfo[nScreenNum].fUserGaveHeightAndWidth)
+ {
+ g_ScreenInfo[nScreenNum].dwWidth_mm
+ = (g_ScreenInfo[nScreenNum].dwWidth
+ / monitorResolution) * 25.4;
+ g_ScreenInfo[nScreenNum].dwHeight_mm
+ = (g_ScreenInfo[nScreenNum].dwHeight
+ / monitorResolution) * 25.4;
+ }
+
+ /* Flag that this screen was explicity specified by the user */
+ g_ScreenInfo[nScreenNum].fExplicitScreen = TRUE;
+
+ /*
+ * Keep track of the last screen number seen, as parameters seen
+ * before a screen number apply to all screens, whereas parameters
+ * seen after a screen number apply to that screen number only.
+ */
+ g_iLastScreen = nScreenNum;
+
+ /* Keep a count of the number of screens */
+ ++g_iNumScreens;
+
+ return iArgsProcessed;
+ }
+
+ /*
+ * Look for the '-engine n' argument
+ */
+ if (IS_OPTION ("-engine"))
+ {
+ DWORD dwEngine = 0;
+ CARD8 c8OnBits = 0;
+
+ /* Display the usage message if the argument is malformed */
+ if (++i >= argc)
+ {
+ UseMsg ();
+ return 0;
+ }
+
+ /* Grab the argument */
+ dwEngine = atoi (argv[i]);
+
+ /* Count the one bits in the engine argument */
+ c8OnBits = winCountBits (dwEngine);
+
+ /* Argument should only have a single bit on */
+ if (c8OnBits != 1)
+ {
+ UseMsg ();
+ return 0;
+ }
+
+ /* Is this parameter attached to a screen or global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].dwEnginePreferred = dwEngine;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].dwEnginePreferred = dwEngine;
+ }
+
+ /* Indicate that we have processed the argument */
+ return 2;
+ }
+
+ /*
+ * Look for the '-fullscreen' argument
+ */
+ if (IS_OPTION ("-fullscreen"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ if (!g_ScreenInfo[j].fMultiMonitorOverride)
+ g_ScreenInfo[j].fMultipleMonitors = FALSE;
+#endif
+ g_ScreenInfo[j].fFullScreen = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
+ g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE;
+#endif
+ g_ScreenInfo[g_iLastScreen].fFullScreen = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-lesspointer' argument
+ */
+ if (IS_OPTION ("-lesspointer"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].fLessPointer = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].fLessPointer = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-nodecoration' argument
+ */
+ if (IS_OPTION ("-nodecoration"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ if (!g_ScreenInfo[j].fMultiMonitorOverride)
+ g_ScreenInfo[j].fMultipleMonitors = FALSE;
+#endif
+ g_ScreenInfo[j].fDecoration = FALSE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
+ g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE;
+#endif
+ g_ScreenInfo[g_iLastScreen].fDecoration = FALSE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+ /*
+ * Look for the '-mwextwm' argument
+ */
+ if (IS_OPTION ("-mwextwm"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ if (!g_ScreenInfo[j].fMultiMonitorOverride)
+ g_ScreenInfo[j].fMultipleMonitors = TRUE;
+ g_ScreenInfo[j].fMWExtWM = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
+ g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE;
+ g_ScreenInfo[g_iLastScreen].fMWExtWM = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+ /*
+ * Look for the '-internalwm' argument
+ */
+ if (IS_OPTION ("-internalwm"))
+ {
+ /* 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++)
+ {
+ if (!g_ScreenInfo[j].fMultiMonitorOverride)
+ g_ScreenInfo[j].fMultipleMonitors = TRUE;
+ g_ScreenInfo[j].fMWExtWM = TRUE;
+ g_ScreenInfo[j].fInternalWM = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
+ g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE;
+ g_ScreenInfo[g_iLastScreen].fMWExtWM = TRUE;
+ g_ScreenInfo[g_iLastScreen].fInternalWM = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+#endif
+
+ /*
+ * Look for the '-rootless' argument
+ */
+ if (IS_OPTION ("-rootless"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ if (!g_ScreenInfo[j].fMultiMonitorOverride)
+ g_ScreenInfo[j].fMultipleMonitors = FALSE;
+#endif
+ g_ScreenInfo[j].fRootless = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
+ g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE;
+#endif
+ g_ScreenInfo[g_iLastScreen].fRootless = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+#ifdef XWIN_MULTIWINDOW
+ /*
+ * Look for the '-multiwindow' argument
+ */
+ if (IS_OPTION ("-multiwindow"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ if (!g_ScreenInfo[j].fMultiMonitorOverride)
+ g_ScreenInfo[j].fMultipleMonitors = TRUE;
+#endif
+ g_ScreenInfo[j].fMultiWindow = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ if (!g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride)
+ g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE;
+#endif
+ g_ScreenInfo[g_iLastScreen].fMultiWindow = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+#endif
+
+ /*
+ * Look for the '-multiplemonitors' argument
+ */
+ if (IS_OPTION ("-multiplemonitors")
+ || IS_OPTION ("-multimonitors"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ g_ScreenInfo[j].fMultiMonitorOverride = TRUE;
+#endif
+ g_ScreenInfo[j].fMultipleMonitors = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride = TRUE;
+#endif
+ g_ScreenInfo[g_iLastScreen].fMultipleMonitors = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-nomultiplemonitors' argument
+ */
+ if (IS_OPTION ("-nomultiplemonitors")
+ || IS_OPTION ("-nomultimonitors"))
+ {
+ /* 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++)
+ {
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ g_ScreenInfo[j].fMultiMonitorOverride = TRUE;
+#endif
+ g_ScreenInfo[j].fMultipleMonitors = FALSE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ g_ScreenInfo[g_iLastScreen].fMultiMonitorOverride = TRUE;
+#endif
+ g_ScreenInfo[g_iLastScreen].fMultipleMonitors = FALSE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+
+ /*
+ * Look for the '-scrollbars' argument
+ */
+ if (IS_OPTION ("-scrollbars"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].fScrollbars = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].fScrollbars = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+
+#ifdef XWIN_CLIPBOARD
+ /*
+ * Look for the '-clipboard' argument
+ */
+ if (IS_OPTION ("-clipboard"))
+ {
+ /* Now the default, we still accept the arg for backwards compatibility */
+ g_fClipboard = TRUE;
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-noclipboard' argument
+ */
+ if (IS_OPTION ("-noclipboard"))
+ {
+ g_fClipboard = FALSE;
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+#endif
+
+
+ /*
+ * Look for the '-ignoreinput' argument
+ */
+ if (IS_OPTION ("-ignoreinput"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].fIgnoreInput = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].fIgnoreInput = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-emulate3buttons' argument
+ */
+ if (IS_OPTION ("-emulate3buttons"))
+ {
+ int iArgsProcessed = 1;
+ int iE3BTimeout = WIN_DEFAULT_E3B_TIME;
+
+ /* Grab the optional timeout value */
+ if (i + 1 < argc
+ && 1 == sscanf (argv[i + 1], "%d",
+ &iE3BTimeout))
+ {
+ /* Indicate that we have processed the next argument */
+ iArgsProcessed++;
+ }
+ else
+ {
+ /*
+ * sscanf () won't modify iE3BTimeout if it doesn't find
+ * the specified format; however, I want to be explicit
+ * about setting the default timeout in such cases to
+ * prevent some programs (me) from getting confused.
+ */
+ iE3BTimeout = WIN_DEFAULT_E3B_TIME;
+ }
+
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].iE3BTimeout = iE3BTimeout;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].iE3BTimeout = iE3BTimeout;
+ }
+
+ /* Indicate that we have processed this argument */
+ return iArgsProcessed;
+ }
+
+ /*
+ * Look for the '-depth n' argument
+ */
+ if (IS_OPTION ("-depth"))
+ {
+ DWORD dwBPP = 0;
+
+ /* Display the usage message if the argument is malformed */
+ if (++i >= argc)
+ {
+ UseMsg ();
+ return 0;
+ }
+
+ /* Grab the argument */
+ dwBPP = atoi (argv[i]);
+
+ /* Is this parameter attached to a screen or global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].dwBPP = dwBPP;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].dwBPP = dwBPP;
+ }
+
+ /* Indicate that we have processed the argument */
+ return 2;
+ }
+
+ /*
+ * Look for the '-refresh n' argument
+ */
+ if (IS_OPTION ("-refresh"))
+ {
+ DWORD dwRefreshRate = 0;
+
+ /* Display the usage message if the argument is malformed */
+ if (++i >= argc)
+ {
+ UseMsg ();
+ return 0;
+ }
+
+ /* Grab the argument */
+ dwRefreshRate = atoi (argv[i]);
+
+ /* Is this parameter attached to a screen or global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].dwRefreshRate = dwRefreshRate;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].dwRefreshRate = dwRefreshRate;
+ }
+
+ /* Indicate that we have processed the argument */
+ return 2;
+ }
+
+ /*
+ * Look for the '-clipupdates num_boxes' argument
+ */
+ if (IS_OPTION ("-clipupdates"))
+ {
+ DWORD dwNumBoxes = 0;
+
+ /* Display the usage message if the argument is malformed */
+ if (++i >= argc)
+ {
+ UseMsg ();
+ return 0;
+ }
+
+ /* Grab the argument */
+ dwNumBoxes = atoi (argv[i]);
+
+ /* Is this parameter attached to a screen or global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].dwClipUpdatesNBoxes = dwNumBoxes;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].dwClipUpdatesNBoxes = dwNumBoxes;
+ }
+
+ /* Indicate that we have processed the argument */
+ return 2;
+ }
+
+#ifdef XWIN_EMULATEPSEUDO
+ /*
+ * Look for the '-emulatepseudo' argument
+ */
+ if (IS_OPTION ("-emulatepseudo"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].fEmulatePseudo = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].fEmulatePseudo = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+#endif
+
+ /*
+ * Look for the '-nowinkill' argument
+ */
+ if (IS_OPTION ("-nowinkill"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].fUseWinKillKey = FALSE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].fUseWinKillKey = FALSE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-winkill' argument
+ */
+ if (IS_OPTION ("-winkill"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].fUseWinKillKey = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].fUseWinKillKey = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-nounixkill' argument
+ */
+ if (IS_OPTION ("-nounixkill"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].fUseUnixKillKey = FALSE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = FALSE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-unixkill' argument
+ */
+ if (IS_OPTION ("-unixkill"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].fUseUnixKillKey = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].fUseUnixKillKey = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-notrayicon' argument
+ */
+ if (IS_OPTION ("-notrayicon"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].fNoTrayIcon = TRUE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].fNoTrayIcon = TRUE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-trayicon' argument
+ */
+ if (IS_OPTION ("-trayicon"))
+ {
+ /* Is this parameter attached to a screen or is it global? */
+ if (-1 == g_iLastScreen)
+ {
+ int j;
+
+ /* Parameter is for all screens */
+ for (j = 0; j < MAXSCREENS; j++)
+ {
+ g_ScreenInfo[j].fNoTrayIcon = FALSE;
+ }
+ }
+ else
+ {
+ /* Parameter is for a single screen */
+ g_ScreenInfo[g_iLastScreen].fNoTrayIcon = FALSE;
+ }
+
+ /* Indicate that we have processed this argument */
+ return 1;
+ }
+
+ /*
+ * Look for the '-fp' argument
+ */
+ if (IS_OPTION ("-fp"))
+ {
+ CHECK_ARGS (1);
+ g_cmdline.fontPath = argv[++i];
+ return 0; /* Let DIX parse this again */
+ }
+
+ /*
+ * Look for the '-query' argument
+ */
+ if (IS_OPTION ("-query"))
+ {
+ CHECK_ARGS (1);
+ g_fXdmcpEnabled = TRUE;
+ g_pszQueryHost = argv[++i];
+ return 0; /* Let DIX parse this again */
+ }
+
+ /*
+ * Look for the '-auth' argument
+ */
+ if (IS_OPTION ("-auth"))
+ {
+ g_fAuthEnabled = TRUE;
+ return 0; /* Let DIX parse this again */
+ }
+
+ /*
+ * Look for the '-indirect' or '-broadcast' arguments
+ */
+ if (IS_OPTION ("-indirect")
+ || IS_OPTION ("-broadcast"))
+ {
+ g_fXdmcpEnabled = TRUE;
+ return 0; /* Let DIX parse this again */
+ }
+
+ /*
+ * Look for the '-config' argument
+ */
+ if (IS_OPTION ("-config")
+ || IS_OPTION ("-xf86config"))
+ {
+ CHECK_ARGS (1);
+#ifdef XWIN_XF86CONFIG
+ g_cmdline.configFile = argv[++i];
+#else
+ winMessageBoxF ("The %s option is not supported in this "
+ "release.\n"
+ "Ignoring this option and continuing.\n",
+ MB_ICONINFORMATION,
+ argv[i]);
+#endif
+ return 2;
+ }
+
+ /*
+ * Look for the '-keyboard' argument
+ */
+ if (IS_OPTION ("-keyboard"))
+ {
+#ifdef XWIN_XF86CONFIG
+ CHECK_ARGS (1);
+ g_cmdline.keyboard = argv[++i];
+#else
+ winMessageBoxF ("The -keyboard option is not supported in this "
+ "release.\n"
+ "Ignoring this option and continuing.\n",
+ MB_ICONINFORMATION);
+#endif
+ return 2;
+ }
+
+ /*
+ * Look for the '-logfile' argument
+ */
+ if (IS_OPTION ("-logfile"))
+ {
+ CHECK_ARGS (1);
+ g_pszLogFile = argv[++i];
+#ifdef RELOCATE_PROJECTROOT
+ g_fLogFileChanged = TRUE;
+#endif
+ return 2;
+ }
+
+ /*
+ * Look for the '-logverbose' argument
+ */
+ if (IS_OPTION ("-logverbose"))
+ {
+ CHECK_ARGS (1);
+ g_iLogVerbose = atoi(argv[++i]);
+ return 2;
+ }
+
+#ifdef XWIN_CLIPBOARD
+ /*
+ * Look for the '-nounicodeclipboard' argument
+ */
+ if (IS_OPTION ("-nounicodeclipboard"))
+ {
+ g_fUnicodeClipboard = FALSE;
+ /* Indicate that we have processed the argument */
+ return 1;
+ }
+#endif
+
+ if (IS_OPTION ("-xkbrules"))
+ {
+ CHECK_ARGS (1);
+ g_cmdline.xkbRules = argv[++i];
+ return 2;
+ }
+ if (IS_OPTION ("-xkbmodel"))
+ {
+ CHECK_ARGS (1);
+ g_cmdline.xkbModel = argv[++i];
+ return 2;
+ }
+ if (IS_OPTION ("-xkblayout"))
+ {
+ CHECK_ARGS (1);
+ g_cmdline.xkbLayout = argv[++i];
+ return 2;
+ }
+ if (IS_OPTION ("-xkbvariant"))
+ {
+ CHECK_ARGS (1);
+ g_cmdline.xkbVariant = argv[++i];
+ return 2;
+ }
+ if (IS_OPTION ("-xkboptions"))
+ {
+ CHECK_ARGS (1);
+ g_cmdline.xkbOptions = argv[++i];
+ return 2;
+ }
+
+ if (IS_OPTION ("-keyhook"))
+ {
+ g_fKeyboardHookLL = TRUE;
+ return 1;
+ }
+
+ if (IS_OPTION ("-nokeyhook"))
+ {
+ g_fKeyboardHookLL = FALSE;
+ return 1;
+ }
+
+ if (IS_OPTION ("-swcursor"))
+ {
+ g_fSoftwareCursor = TRUE;
+ return 1;
+ }
+
+ if (IS_OPTION ("-silent-dup-error"))
+ {
+ g_fSilentDupError = TRUE;
+ return 1;
+ }
+ return 0;
+}
+
+
+/*
+ * winLogCommandLine - Write entire command line to the log file
+ */
+
+void
+winLogCommandLine (int argc, char *argv[])
+{
+ int i;
+ int iSize = 0;
+ int iCurrLen = 0;
+
+#define CHARS_PER_LINE 60
+
+ /* Bail if command line has already been logged */
+ if (g_pszCommandLine)
+ return;
+
+ /* Count how much memory is needed for concatenated command line */
+ for (i = 0, iCurrLen = 0; i < argc; ++i)
+ if (argv[i])
+ {
+ /* Adds two characters for lines that overflow */
+ if ((strlen (argv[i]) < CHARS_PER_LINE
+ && iCurrLen + strlen (argv[i]) > CHARS_PER_LINE)
+ || strlen (argv[i]) > CHARS_PER_LINE)
+ {
+ iCurrLen = 0;
+ iSize += 2;
+ }
+
+ /* Add space for item and trailing space */
+ iSize += strlen (argv[i]) + 1;
+
+ /* Update current line length */
+ iCurrLen += strlen (argv[i]);
+ }
+
+ /* Allocate memory for concatenated command line */
+ g_pszCommandLine = malloc (iSize + 1);
+ if (!g_pszCommandLine)
+ FatalError ("winLogCommandLine - Could not allocate memory for "
+ "command line string. Exiting.\n");
+
+ /* Set first character to concatenated command line to null */
+ g_pszCommandLine[0] = '\0';
+
+ /* Loop through all args */
+ for (i = 0, iCurrLen = 0; i < argc; ++i)
+ {
+ /* Add a character for lines that overflow */
+ if ((strlen (argv[i]) < CHARS_PER_LINE
+ && iCurrLen + strlen (argv[i]) > CHARS_PER_LINE)
+ || strlen (argv[i]) > CHARS_PER_LINE)
+ {
+ iCurrLen = 0;
+
+ /* Add line break if it fits */
+ strncat (g_pszCommandLine, "\n ", iSize - strlen (g_pszCommandLine));
+ }
+
+ strncat (g_pszCommandLine, argv[i], iSize - strlen (g_pszCommandLine));
+ strncat (g_pszCommandLine, " ", iSize - strlen (g_pszCommandLine));
+
+ /* Save new line length */
+ iCurrLen += strlen (argv[i]);
+ }
+
+ winDebug ("XWin was started with the following command line:\n\n"
+ "%s\n\n", g_pszCommandLine);
+}
+
+
+/*
+ * winLogVersionInfo - Log Cygwin/X version information
+ */
+
+void
+winLogVersionInfo (void)
+{
+#ifdef WINDBG
+ static Bool s_fBeenHere = FALSE;
+
+ if (s_fBeenHere)
+ return;
+ s_fBeenHere = TRUE;
+
+ winDebug ("Welcome to the VcXsrv X Server\n");
+ winDebug ("Vendor: %s\n", VENDOR_STRING);
+ winDebug ("Release: %d.%d.%d.%d (%d)\n\n", XORG_VERSION_MAJOR, XORG_VERSION_MINOR, XORG_VERSION_PATCH, XORG_VERSION_SNAP, XORG_VERSION_CURRENT);
+ winDebug ("Contact: %s\n\n", VENDOR_CONTACT);
+#endif
+}
+/*
+ * getMonitorInfo - callback function used to return information from the enumeration of monitors attached
+ */
+
+wBOOL CALLBACK getMonitorInfo(HMONITOR hMonitor, HDC hdc, LPRECT rect, LPARAM _data)
+{
+ struct GetMonitorInfoData* data = (struct GetMonitorInfoData*)_data;
+ // only get data for monitor number specified in <data>
+ data->monitorNum++;
+ if (data->monitorNum == data->requestedMonitor)
+ {
+ data->bMonitorSpecifiedExists = TRUE;
+ data->monitorOffsetX = rect->left;
+ data->monitorOffsetY = rect->top;
+ data->monitorHeight = rect->bottom - rect->top;
+ data->monitorWidth = rect->right - rect->left;
+ return FALSE;
+ }
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/winscrinit.c b/xorg-server/hw/xwin/winscrinit.c index b97b6a0de..db65a5eed 100644 --- a/xorg-server/hw/xwin/winscrinit.c +++ b/xorg-server/hw/xwin/winscrinit.c @@ -1,768 +1,777 @@ -/* - *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved. - * - *Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - *"Software"), to deal in the Software without restriction, including - *without limitation the rights to use, copy, modify, merge, publish, - *distribute, sublicense, and/or sell copies of the Software, and to - *permit persons to whom the Software is furnished to do so, subject to - *the following conditions: - * - *The above copyright notice and this permission notice shall be - *included in all copies or substantial portions of the Software. - * - *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR - *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF - *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - *Except as contained in this notice, the name of the XFree86 Project - *shall not be used in advertising or otherwise to promote the sale, use - *or other dealings in this Software without prior written authorization - *from the XFree86 Project. - * - * Authors: Dakshinamurthy Karra - * Suhaib M Siddiqi - * Peter Busch - * Harold L Hunt II - * Kensuke Matsuzaki - */ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" -#include "winmsg.h" - - -#ifdef XWIN_MULTIWINDOWEXTWM -static RootlessFrameProcsRec -winMWExtWMProcs = { - winMWExtWMCreateFrame, - winMWExtWMDestroyFrame, - - winMWExtWMMoveFrame, - winMWExtWMResizeFrame, - winMWExtWMRestackFrame, - winMWExtWMReshapeFrame, - winMWExtWMUnmapFrame, - - winMWExtWMStartDrawing, - winMWExtWMStopDrawing, - winMWExtWMUpdateRegion, -#ifndef ROOTLESS_TRACK_DAMAGE - winMWExtWMDamageRects, -#endif - winMWExtWMRootlessSwitchWindow, - NULL,//winMWExtWMDoReorderWindow, - NULL,//winMWExtWMHideWindow, - NULL,//winMWExtWMUpdateColorMap, - - NULL,//winMWExtWMCopyBytes, - NULL,//winMWExtWMFillBytes, - NULL,//winMWExtWMCompositePixels, - winMWExtWMCopyWindow -}; -#endif - - -/* - * References to external symbols - */ - -extern Bool g_fSoftwareCursor; - - -/* - * Prototypes - */ - -Bool -winRandRInit (ScreenPtr pScreen); - - -/* - * Local functions - */ - -static Bool -winSaveScreen (ScreenPtr pScreen, int on); - - -/* - * Determine what type of screen we are initializing - * and call the appropriate procedure to intiailize - * that type of screen. - */ - -Bool -winScreenInit (int index, - ScreenPtr pScreen, - int argc, char **argv) -{ - winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index]; - winPrivScreenPtr pScreenPriv; - HDC hdc; - - winDebug ("winScreenInit - dwWidth: %ld dwHeight: %ld\n", - pScreenInfo->dwWidth, pScreenInfo->dwHeight); - - /* Allocate privates for this screen */ - if (!winAllocatePrivates (pScreen)) - { - ErrorF ("winScreenInit - Couldn't allocate screen privates\n"); - return FALSE; - } - - /* Get a pointer to the privates structure that was allocated */ - pScreenPriv = winGetScreenPriv (pScreen); - - /* Save a pointer to this screen in the screen info structure */ - pScreenInfo->pScreen = pScreen; - - /* Save a pointer to the screen info in the screen privates structure */ - /* This allows us to get back to the screen info from a screen pointer */ - pScreenPriv->pScreenInfo = pScreenInfo; - - /* - * Determine which engine to use. - * - * NOTE: This is done once per screen because each screen possibly has - * a preferred engine specified on the command line. - */ - if (!winSetEngine (pScreen)) - { - ErrorF ("winScreenInit - winSetEngine () failed\n"); - return FALSE; - } - - /* Adjust the video mode for our engine type */ - if (pScreenPriv->pwinAdjustVideoMode && !(*pScreenPriv->pwinAdjustVideoMode) (pScreen)) - { - ErrorF ("winScreenInit - winAdjustVideoMode () failed\n"); - return FALSE; - } - - /* Check for supported display depth */ - if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1)))) - { - ErrorF ("winScreenInit - Unsupported display depth: %d\n" \ - "Change your Windows display depth to 15, 16, 24, or 32 bits " - "per pixel.\n", - (int) pScreenInfo->dwBPP); - ErrorF ("winScreenInit - Supported depths: %08x\n", - WIN_SUPPORTED_BPPS); -#if WIN_CHECK_DEPTH - return FALSE; -#endif - } - - /* - * Check that all monitors have the same display depth if we are using - * multiple monitors - */ - if (pScreenInfo->fMultipleMonitors - && !GetSystemMetrics (SM_SAMEDISPLAYFORMAT)) - { - ErrorF ("winScreenInit - Monitors do not all have same pixel format / " - "display depth.\n" - "Using primary display only.\n"); - pScreenInfo->fMultipleMonitors = FALSE; - } - - /* Create display window */ - if (pScreenPriv->pwinCreateBoundingWindow && !(*pScreenPriv->pwinCreateBoundingWindow) (pScreen)) - { - ErrorF ("winScreenInit - pwinCreateBoundingWindow () " - "failed\n"); - return FALSE; - } - - /* Get a device context */ - hdc = GetDC (pScreenPriv->hwndScreen); - - /* Store the initial height, width, and depth of the display */ - /* Are we using multiple monitors? */ - if (pScreenInfo->fMultipleMonitors) - { - pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN); - pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN); - - /* - * In this case, some of the defaults set in - * winInitializeDefaultScreens () are not correct ... - */ - if (!pScreenInfo->fUserGaveHeightAndWidth) - { - pScreenInfo->dwWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN); - pScreenInfo->dwHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN); - pScreenInfo->dwWidth_mm = (pScreenInfo->dwWidth / - WIN_DEFAULT_DPI) * 25.4; - pScreenInfo->dwHeight_mm = (pScreenInfo->dwHeight / - WIN_DEFAULT_DPI) * 25.4; - } - } - else - { - pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXSCREEN); - pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYSCREEN); - } - - /* Save the original bits per pixel */ - pScreenPriv->dwLastWindowsBitsPixel = GetDeviceCaps (hdc, BITSPIXEL); - - /* Release the device context */ - ReleaseDC (pScreenPriv->hwndScreen, hdc); - - /* Clear the visuals list */ - miClearVisualTypes (); - - /* Set the padded screen width */ - pScreenInfo->dwPaddedWidth = PixmapBytePad (pScreenInfo->dwWidth, - pScreenInfo->dwBPP); - - /* Call the engine dependent screen initialization procedure */ - if (pScreenPriv->pwinFinishScreenInit && !((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv))) - { - ErrorF ("winScreenInit - winFinishScreenInit () failed\n"); - return FALSE; - } - - if (!g_fSoftwareCursor) - winInitCursor(pScreen); -#ifdef WINDBG - else - winDebug("winScreenInit - Using software cursor\n"); -#endif - - winDebug ("winScreenInit - returning\n"); - - return TRUE; -} - -static Bool -winCreateScreenResources(ScreenPtr pScreen) -{ - winScreenPriv(pScreen); - Bool result; - - result = pScreenPriv->pwinCreateScreenResources(pScreen); - - /* Now the screen bitmap has been wrapped in a pixmap, - add that to the Shadow framebuffer */ - if (!shadowAdd(pScreen, pScreen->devPrivate, - pScreenPriv->pwinShadowUpdate, NULL, 0, 0)) - { - ErrorF ("winCreateScreenResources - shadowAdd () failed\n"); - return FALSE; - } - - return result; -} - -/* See Porting Layer Definition - p. 20 */ -Bool -winFinishScreenInitFB (int index, - ScreenPtr pScreen, - int argc, char **argv) -{ - winScreenPriv(pScreen); - winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo; - VisualPtr pVisual = NULL; - char *pbits = NULL; -#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) - int iReturn; -#endif - - /* Create framebuffer */ - if (!(*pScreenPriv->pwinAllocateFB) (pScreen)) - { - ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n"); - return FALSE; - } - - /* - * Grab the number of bits that are used to represent color in each pixel. - */ - if (pScreenInfo->dwBPP == 8) - pScreenInfo->dwDepth = 8; - else - pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask) - + winCountBits (pScreenPriv->dwGreenMask) - + winCountBits (pScreenPriv->dwBlueMask); - - winDebug ("winFinishScreenInitFB - Masks: %08x %08x %08x\n", - (unsigned int) pScreenPriv->dwRedMask, - (unsigned int) pScreenPriv->dwGreenMask, - (unsigned int) pScreenPriv->dwBlueMask); - - /* Init visuals */ - if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) - { - ErrorF ("winFinishScreenInitFB - winInitVisuals failed\n"); - return FALSE; - } - - /* Setup a local variable to point to the framebuffer */ - pbits = pScreenInfo->pfb; - - /* Apparently we need this for the render extension */ - miSetPixmapDepths (); - - /* Start fb initialization */ - if (!fbSetupScreen (pScreen, - pScreenInfo->pfb, - pScreenInfo->dwWidth, pScreenInfo->dwHeight, - monitorResolution, monitorResolution, - pScreenInfo->dwStride, - pScreenInfo->dwBPP)) - { - ErrorF ("winFinishScreenInitFB - fbSetupScreen failed\n"); - return FALSE; - } - - /* Override default colormap routines if visual class is dynamic */ - if (pScreenInfo->dwDepth == 8 - && (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI - || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL - && pScreenInfo->fFullScreen) - || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD - && pScreenInfo->fFullScreen))) - { - winSetColormapFunctions (pScreen); - - /* - * NOTE: Setting whitePixel to 255 causes Magic 7.1 to allocate its - * own colormap, as it cannot allocate 7 planes in the default - * colormap. Setting whitePixel to 1 allows Magic to get 7 - * planes in the default colormap, so it doesn't create its - * own colormap. This latter situation is highly desireable, - * as it keeps the Magic window viewable when switching to - * other X clients that use the default colormap. - */ - pScreen->blackPixel = 0; - pScreen->whitePixel = 1; - } - - /* Place our save screen function */ - pScreen->SaveScreen = winSaveScreen; - - /* Finish fb initialization */ - if (!fbFinishScreenInit (pScreen, - pScreenInfo->pfb, - pScreenInfo->dwWidth, pScreenInfo->dwHeight, - monitorResolution, monitorResolution, - pScreenInfo->dwStride, - pScreenInfo->dwBPP)) - { - ErrorF ("winFinishScreenInitFB - fbFinishScreenInit failed\n"); - return FALSE; - } - - /* Save a pointer to the root visual */ - for (pVisual = pScreen->visuals; - pVisual->vid != pScreen->rootVisual; - pVisual++); - pScreenPriv->pRootVisual = pVisual; - - /* - * Setup points to the block and wakeup handlers. Pass a pointer - * to the current screen as pWakeupdata. - */ - pScreen->BlockHandler = winBlockHandler; - pScreen->WakeupHandler = winWakeupHandler; - pScreen->blockData = pScreen; - pScreen->wakeupData = pScreen; - -#ifdef RENDER - /* Render extension initialization, calls miPictureInit */ - if (!fbPictureInit (pScreen, NULL, 0)) - { - ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n"); - return FALSE; - } -#endif - -#ifdef RANDR - /* Initialize resize and rotate support */ - if (!winRandRInit (pScreen)) - { - ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n"); - return FALSE; - } -#endif - - /* - * Backing store support should reduce network traffic and increase - * performance. - */ - miInitializeBackingStore (pScreen); - - /* KDrive does miDCInitialize right after miInitializeBackingStore */ - /* Setup the cursor routines */ - winDebug ("winFinishScreenInitFB - Calling miDCInitialize ()\n"); - miDCInitialize (pScreen, &g_winPointerCursorFuncs); - - /* KDrive does winCreateDefColormap right after miDCInitialize */ - /* Create a default colormap */ - winDebug ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n"); - if (!winCreateDefColormap (pScreen)) - { - ErrorF ("winFinishScreenInitFB - Could not create colormap\n"); - return FALSE; - } - - /* Initialize the shadow framebuffer layer */ - if ((pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI - || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD - || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL) -#ifdef XWIN_MULTIWINDOWEXTWM - && !pScreenInfo->fMWExtWM -#endif - ) - { - winDebug ("winFinishScreenInitFB - Calling shadowSetup ()\n"); - if (!shadowSetup(pScreen)) - { - ErrorF ("winFinishScreenInitFB - shadowSetup () failed\n"); - return FALSE; - } - - /* Wrap CreateScreenResources so we can add the screen pixmap - to the Shadow framebuffer after it's been created */ - pScreenPriv->pwinCreateScreenResources = pScreen->CreateScreenResources; - pScreen->CreateScreenResources = winCreateScreenResources; - } - -#ifdef XWIN_MULTIWINDOWEXTWM - /* Handle multi-window external window manager mode */ - if (pScreenInfo->fMWExtWM) - { - winDebug ("winScreenInit - MultiWindowExtWM - Calling RootlessInit\n"); - - RootlessInit(pScreen, &winMWExtWMProcs); - - winDebug ("winScreenInit - MultiWindowExtWM - RootlessInit returned\n"); - - rootless_CopyBytes_threshold = 0; - rootless_FillBytes_threshold = 0; - rootless_CompositePixels_threshold = 0; - /* FIXME: How many? Profiling needed? */ - rootless_CopyWindow_threshold = 1; - - winWindowsWMExtensionInit (); - } -#endif - - /* Handle rootless mode */ - if (pScreenInfo->fRootless) - { - /* Define the WRAP macro temporarily for local use */ -#define WRAP(a) \ - if (pScreen->a) { \ - pScreenPriv->a = pScreen->a; \ - } else { \ - ErrorF("null screen fn " #a "\n"); \ - pScreenPriv->a = NULL; \ - } - - /* Save a pointer to each lower-level window procedure */ - WRAP(CreateWindow); - WRAP(DestroyWindow); - WRAP(RealizeWindow); - WRAP(UnrealizeWindow); - WRAP(PositionWindow); - WRAP(ChangeWindowAttributes); - WRAP(SetShape); - - /* Assign rootless window procedures to be top level procedures */ - pScreen->CreateWindow = winCreateWindowRootless; - pScreen->DestroyWindow = winDestroyWindowRootless; - pScreen->PositionWindow = winPositionWindowRootless; - /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesRootless;*/ - pScreen->RealizeWindow = winMapWindowRootless; - pScreen->UnrealizeWindow = winUnmapWindowRootless; - pScreen->SetShape = winSetShapeRootless; - - /* Undefine the WRAP macro, as it is not needed elsewhere */ -#undef WRAP - } - - -#ifdef XWIN_MULTIWINDOW - /* Handle multi window mode */ - else if (pScreenInfo->fMultiWindow) - { - /* Define the WRAP macro temporarily for local use */ -#define WRAP(a) \ - if (pScreen->a) { \ - pScreenPriv->a = pScreen->a; \ - } else { \ - ErrorF("null screen fn " #a "\n"); \ - pScreenPriv->a = NULL; \ - } - - /* Save a pointer to each lower-level window procedure */ - WRAP(CreateWindow); - WRAP(DestroyWindow); - WRAP(RealizeWindow); - WRAP(UnrealizeWindow); - WRAP(PositionWindow); - WRAP(ChangeWindowAttributes); - WRAP(ReparentWindow); - WRAP(RestackWindow); - WRAP(ResizeWindow); - WRAP(MoveWindow); - WRAP(CopyWindow); - WRAP(SetShape); - - /* Assign multi-window window procedures to be top level procedures */ - pScreen->CreateWindow = winCreateWindowMultiWindow; - pScreen->DestroyWindow = winDestroyWindowMultiWindow; - pScreen->PositionWindow = winPositionWindowMultiWindow; - /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesMultiWindow;*/ - pScreen->RealizeWindow = winMapWindowMultiWindow; - pScreen->UnrealizeWindow = winUnmapWindowMultiWindow; - pScreen->ReparentWindow = winReparentWindowMultiWindow; - pScreen->RestackWindow = winRestackWindowMultiWindow; - pScreen->ResizeWindow = winResizeWindowMultiWindow; - pScreen->MoveWindow = winMoveWindowMultiWindow; - pScreen->CopyWindow = winCopyWindowMultiWindow; - pScreen->SetShape = winSetShapeMultiWindow; - - /* Undefine the WRAP macro, as it is not needed elsewhere */ -#undef WRAP - } -#endif - - /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */ - pScreenPriv->CloseScreen = pScreen->CloseScreen; - pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; - -#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW) - /* Create a mutex for modules in separate threads to wait for */ - iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL); - if (iReturn != 0) - { - ErrorF ("winFinishScreenInitFB - pthread_mutex_init () failed: %d\n", - iReturn); - return FALSE; - } - - /* Own the mutex for modules in separate threads */ - iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted); - if (iReturn != 0) - { - ErrorF ("winFinishScreenInitFB - pthread_mutex_lock () failed: %d\n", - iReturn); - return FALSE; - } - - /* Set the ServerStarted flag to false */ - pScreenPriv->fServerStarted = FALSE; -#endif - -#ifdef XWIN_MULTIWINDOWEXTWM - pScreenPriv->fRestacking = FALSE; -#endif - -#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM) - if (FALSE -#ifdef XWIN_MULTIWINDOW - || pScreenInfo->fMultiWindow -#endif -#ifdef XWIN_MULTIWINDOWEXTWM - || pScreenInfo->fInternalWM -#endif - ) - { - winDebug ("winFinishScreenInitFB - Calling winInitWM.\n"); - - /* Initialize multi window mode */ - if (!winInitWM (&pScreenPriv->pWMInfo, - &pScreenPriv->ptWMProc, - &pScreenPriv->ptXMsgProc, - &pScreenPriv->pmServerStarted, - pScreenInfo->dwScreen, - (HWND)&pScreenPriv->hwndScreen, -#ifdef XWIN_MULTIWINDOWEXTWM - pScreenInfo->fInternalWM || -#endif - FALSE)) - { - ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n"); - return FALSE; - } - } -#endif - - /* Tell the server that we are enabled */ - pScreenPriv->fEnabled = TRUE; - - /* Tell the server that we have a valid depth */ - pScreenPriv->fBadDepth = FALSE; - - winDebug ("winFinishScreenInitFB - returning\n"); - - return TRUE; -} - -#ifdef XWIN_NATIVEGDI -/* See Porting Layer Definition - p. 20 */ - -Bool -winFinishScreenInitNativeGDI (int index, - ScreenPtr pScreen, - int argc, char **argv) -{ - winScreenPriv(pScreen); - winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index]; - VisualPtr pVisuals = NULL; - DepthPtr pDepths = NULL; - VisualID rootVisual = 0; - int nVisuals = 0, nDepths = 0, nRootDepth = 0; - - /* Ignore user input (mouse, keyboard) */ - pScreenInfo->fIgnoreInput = FALSE; - - /* Get device contexts for the screen and shadow bitmap */ - pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen); - if (pScreenPriv->hdcScreen == NULL) - FatalError ("winFinishScreenInitNativeGDI - Couldn't get a DC\n"); - - /* Init visuals */ - if (!(*pScreenPriv->pwinInitVisuals) (pScreen)) - { - ErrorF ("winFinishScreenInitNativeGDI - pwinInitVisuals failed\n"); - return FALSE; - } - - /* Initialize the mi visuals */ - if (!miInitVisuals (&pVisuals, &pDepths, &nVisuals, &nDepths, &nRootDepth, - &rootVisual, - ((unsigned long)1 << (pScreenInfo->dwDepth - 1)), 8, - TrueColor)) - { - ErrorF ("winFinishScreenInitNativeGDI - miInitVisuals () failed\n"); - return FALSE; - } - - /* Initialize the CloseScreen procedure pointer */ - pScreen->CloseScreen = NULL; - - /* Initialize the mi code */ - if (!miScreenInit (pScreen, - NULL, /* No framebuffer */ - pScreenInfo->dwWidth, pScreenInfo->dwHeight, - monitorResolution, monitorResolution, - pScreenInfo->dwStride, - nRootDepth, nDepths, pDepths, rootVisual, - nVisuals, pVisuals)) - { - ErrorF ("winFinishScreenInitNativeGDI - miScreenInit failed\n"); - return FALSE; - } - - pScreen->defColormap = FakeClientID(0); - - /* - * Register our block and wakeup handlers; these procedures - * process messages in our Windows message queue; specifically, - * they process mouse and keyboard input. - */ - pScreen->BlockHandler = winBlockHandler; - pScreen->WakeupHandler = winWakeupHandler; - pScreen->blockData = pScreen; - pScreen->wakeupData = pScreen; - - /* Place our save screen function */ - pScreen->SaveScreen = winSaveScreen; - - /* Pixmaps */ - pScreen->CreatePixmap = winCreatePixmapNativeGDI; - pScreen->DestroyPixmap = winDestroyPixmapNativeGDI; - - /* Other Screen Routines */ - pScreen->QueryBestSize = winQueryBestSizeNativeGDI; - pScreen->SaveScreen = winSaveScreen; - pScreen->GetImage = miGetImage; - pScreen->GetSpans = winGetSpansNativeGDI; - - /* Window Procedures */ - pScreen->CreateWindow = winCreateWindowNativeGDI; - pScreen->DestroyWindow = winDestroyWindowNativeGDI; - pScreen->PositionWindow = winPositionWindowNativeGDI; - /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesNativeGDI;*/ - pScreen->RealizeWindow = winMapWindowNativeGDI; - pScreen->UnrealizeWindow = winUnmapWindowNativeGDI; - - /* Paint window */ - pScreen->CopyWindow = winCopyWindowNativeGDI; - - /* Fonts */ - pScreen->RealizeFont = winRealizeFontNativeGDI; - pScreen->UnrealizeFont = winUnrealizeFontNativeGDI; - - /* GC */ - pScreen->CreateGC = winCreateGCNativeGDI; - - /* Colormap Routines */ - pScreen->CreateColormap = miInitializeColormap; - pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)(void)) NoopDDA; - pScreen->InstallColormap = miInstallColormap; - pScreen->UninstallColormap = miUninstallColormap; - pScreen->ListInstalledColormaps = miListInstalledColormaps; - pScreen->StoreColors = (StoreColorsProcPtr) (void (*)(void)) NoopDDA; - pScreen->ResolveColor = miResolveColor; - - /* Bitmap */ - pScreen->BitmapToRegion = winPixmapToRegionNativeGDI; - - winDebug ("winFinishScreenInitNativeGDI - calling miDCInitialize\n"); - - /* Set the default white and black pixel positions */ - pScreen->whitePixel = pScreen->blackPixel = (Pixel) 0; - - /* Initialize the cursor */ - if (!miDCInitialize (pScreen, &g_winPointerCursorFuncs)) - { - ErrorF ("winFinishScreenInitNativeGDI - miDCInitialize failed\n"); - return FALSE; - } - - /* Create a default colormap */ - if (!miCreateDefColormap (pScreen)) - { - ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () " - "failed\n"); - return FALSE; - } - - winDebug ("winFinishScreenInitNativeGDI - miCreateDefColormap () " - "returned\n"); - - /* mi doesn't use a CloseScreen procedure, so no need to wrap */ - pScreen->CloseScreen = pScreenPriv->pwinCloseScreen; - - /* Tell the server that we are enabled */ - pScreenPriv->fEnabled = TRUE; - - winDebug ("winFinishScreenInitNativeGDI - Successful addition of " - "screen %08x\n", - (unsigned int) pScreen); - - return TRUE; -} -#endif - - -/* See Porting Layer Definition - p. 33 */ -static Bool -winSaveScreen (ScreenPtr pScreen, int on) -{ - return TRUE; -} +/*
+ *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
+ *
+ *Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ *"Software"), to deal in the Software without restriction, including
+ *without limitation the rights to use, copy, modify, merge, publish,
+ *distribute, sublicense, and/or sell copies of the Software, and to
+ *permit persons to whom the Software is furnished to do so, subject to
+ *the following conditions:
+ *
+ *The above copyright notice and this permission notice shall be
+ *included in all copies or substantial portions of the Software.
+ *
+ *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
+ *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
+ *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *Except as contained in this notice, the name of the XFree86 Project
+ *shall not be used in advertising or otherwise to promote the sale, use
+ *or other dealings in this Software without prior written authorization
+ *from the XFree86 Project.
+ *
+ * Authors: Dakshinamurthy Karra
+ * Suhaib M Siddiqi
+ * Peter Busch
+ * Harold L Hunt II
+ * Kensuke Matsuzaki
+ */
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+#include "winmsg.h"
+
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+static RootlessFrameProcsRec
+winMWExtWMProcs = {
+ winMWExtWMCreateFrame,
+ winMWExtWMDestroyFrame,
+
+ winMWExtWMMoveFrame,
+ winMWExtWMResizeFrame,
+ winMWExtWMRestackFrame,
+ winMWExtWMReshapeFrame,
+ winMWExtWMUnmapFrame,
+
+ winMWExtWMStartDrawing,
+ winMWExtWMStopDrawing,
+ winMWExtWMUpdateRegion,
+#ifndef ROOTLESS_TRACK_DAMAGE
+ winMWExtWMDamageRects,
+#endif
+ winMWExtWMRootlessSwitchWindow,
+ NULL,//winMWExtWMDoReorderWindow,
+ NULL,//winMWExtWMHideWindow,
+ NULL,//winMWExtWMUpdateColorMap,
+
+ NULL,//winMWExtWMCopyBytes,
+ NULL,//winMWExtWMFillBytes,
+ NULL,//winMWExtWMCompositePixels,
+ winMWExtWMCopyWindow
+};
+#endif
+
+
+/*
+ * References to external symbols
+ */
+
+extern Bool g_fSoftwareCursor;
+
+
+/*
+ * Prototypes
+ */
+
+Bool
+winRandRInit (ScreenPtr pScreen);
+
+
+/*
+ * Local functions
+ */
+
+static Bool
+winSaveScreen (ScreenPtr pScreen, int on);
+
+
+/*
+ * Determine what type of screen we are initializing
+ * and call the appropriate procedure to intiailize
+ * that type of screen.
+ */
+
+Bool
+winScreenInit (int index,
+ ScreenPtr pScreen,
+ int argc, char **argv)
+{
+ winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index];
+ winPrivScreenPtr pScreenPriv;
+ HDC hdc;
+
+ winDebug ("winScreenInit - dwWidth: %ld dwHeight: %ld\n",
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight);
+
+ /* Allocate privates for this screen */
+ if (!winAllocatePrivates (pScreen))
+ {
+ ErrorF ("winScreenInit - Couldn't allocate screen privates\n");
+ return FALSE;
+ }
+
+ /* Get a pointer to the privates structure that was allocated */
+ pScreenPriv = winGetScreenPriv (pScreen);
+
+ /* Save a pointer to this screen in the screen info structure */
+ pScreenInfo->pScreen = pScreen;
+
+ /* Save a pointer to the screen info in the screen privates structure */
+ /* This allows us to get back to the screen info from a screen pointer */
+ pScreenPriv->pScreenInfo = pScreenInfo;
+
+ /*
+ * Determine which engine to use.
+ *
+ * NOTE: This is done once per screen because each screen possibly has
+ * a preferred engine specified on the command line.
+ */
+ if (!winSetEngine (pScreen))
+ {
+ ErrorF ("winScreenInit - winSetEngine () failed\n");
+ return FALSE;
+ }
+
+ /* Adjust the video mode for our engine type */
+ if (pScreenPriv->pwinAdjustVideoMode && !(*pScreenPriv->pwinAdjustVideoMode) (pScreen))
+ {
+ ErrorF ("winScreenInit - winAdjustVideoMode () failed\n");
+ return FALSE;
+ }
+
+ /* Check for supported display depth */
+ if (!(WIN_SUPPORTED_BPPS & (1 << (pScreenInfo->dwBPP - 1))))
+ {
+ ErrorF ("winScreenInit - Unsupported display depth: %d\n" \
+ "Change your Windows display depth to 15, 16, 24, or 32 bits "
+ "per pixel.\n",
+ (int) pScreenInfo->dwBPP);
+ ErrorF ("winScreenInit - Supported depths: %08x\n",
+ WIN_SUPPORTED_BPPS);
+#if WIN_CHECK_DEPTH
+ return FALSE;
+#endif
+ }
+
+ /*
+ * Check that all monitors have the same display depth if we are using
+ * multiple monitors
+ */
+ if (pScreenInfo->fMultipleMonitors
+ && !GetSystemMetrics (SM_SAMEDISPLAYFORMAT))
+ {
+ ErrorF ("winScreenInit - Monitors do not all have same pixel format / "
+ "display depth.\n"
+ "Using primary display only.\n");
+ pScreenInfo->fMultipleMonitors = FALSE;
+ }
+
+ /* Create display window */
+ if (pScreenPriv->pwinCreateBoundingWindow && !(*pScreenPriv->pwinCreateBoundingWindow) (pScreen))
+ {
+ ErrorF ("winScreenInit - pwinCreateBoundingWindow () "
+ "failed\n");
+ return FALSE;
+ }
+
+ /* Get a device context */
+ hdc = GetDC (pScreenPriv->hwndScreen);
+
+ /* Store the initial height, width, and depth of the display */
+ /* Are we using multiple monitors? */
+ if (pScreenInfo->fMultipleMonitors)
+ {
+ pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
+ pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
+
+ /*
+ * In this case, some of the defaults set in
+ * winInitializeDefaultScreens () are not correct ...
+ */
+ if (!pScreenInfo->fUserGaveHeightAndWidth)
+ {
+ pScreenInfo->dwWidth = GetSystemMetrics (SM_CXVIRTUALSCREEN);
+ pScreenInfo->dwHeight = GetSystemMetrics (SM_CYVIRTUALSCREEN);
+ pScreenInfo->dwWidth_mm = (pScreenInfo->dwWidth /
+ WIN_DEFAULT_DPI) * 25.4;
+ pScreenInfo->dwHeight_mm = (pScreenInfo->dwHeight /
+ WIN_DEFAULT_DPI) * 25.4;
+ }
+ }
+ else
+ {
+ pScreenPriv->dwLastWindowsWidth = GetSystemMetrics (SM_CXSCREEN);
+ pScreenPriv->dwLastWindowsHeight = GetSystemMetrics (SM_CYSCREEN);
+ }
+
+ /* Save the original bits per pixel */
+ pScreenPriv->dwLastWindowsBitsPixel = GetDeviceCaps (hdc, BITSPIXEL);
+
+ /* Release the device context */
+ ReleaseDC (pScreenPriv->hwndScreen, hdc);
+
+ /* Clear the visuals list */
+ miClearVisualTypes ();
+
+ /* Set the padded screen width */
+ pScreenInfo->dwPaddedWidth = PixmapBytePad (pScreenInfo->dwWidth,
+ pScreenInfo->dwBPP);
+
+ /* Call the engine dependent screen initialization procedure */
+ if (pScreenPriv->pwinFinishScreenInit && !((*pScreenPriv->pwinFinishScreenInit) (index, pScreen, argc, argv)))
+ {
+ ErrorF ("winScreenInit - winFinishScreenInit () failed\n");
+ return FALSE;
+ }
+
+ if (!g_fSoftwareCursor)
+ winInitCursor(pScreen);
+#ifdef WINDBG
+ else
+ winDebug("winScreenInit - Using software cursor\n");
+#endif
+
+ /*
+ Note the screen origin in a normalized coordinate space where (0,0) is at the top left
+ of the native virtual desktop area
+ */
+ dixScreenOrigins[index].x = pScreenInfo->dwInitialX - GetSystemMetrics(SM_XVIRTUALSCREEN);
+ dixScreenOrigins[index].y = pScreenInfo->dwInitialY - GetSystemMetrics(SM_YVIRTUALSCREEN);
+
+ winDebug("Screen %d added at XINERAMA coordinate (%d,%d).\n",
+ index, dixScreenOrigins[index].x, dixScreenOrigins[index].y);
+ winDebug ("winScreenInit - returning\n");
+
+ return TRUE;
+}
+
+static Bool
+winCreateScreenResources(ScreenPtr pScreen)
+{
+ winScreenPriv(pScreen);
+ Bool result;
+
+ result = pScreenPriv->pwinCreateScreenResources(pScreen);
+
+ /* Now the screen bitmap has been wrapped in a pixmap,
+ add that to the Shadow framebuffer */
+ if (!shadowAdd(pScreen, pScreen->devPrivate,
+ pScreenPriv->pwinShadowUpdate, NULL, 0, 0))
+ {
+ ErrorF ("winCreateScreenResources - shadowAdd () failed\n");
+ return FALSE;
+ }
+
+ return result;
+}
+
+/* See Porting Layer Definition - p. 20 */
+Bool
+winFinishScreenInitFB (int index,
+ ScreenPtr pScreen,
+ int argc, char **argv)
+{
+ winScreenPriv(pScreen);
+ winScreenInfo *pScreenInfo = pScreenPriv->pScreenInfo;
+ VisualPtr pVisual = NULL;
+ char *pbits = NULL;
+#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+ int iReturn;
+#endif
+
+ /* Create framebuffer */
+ if (!(*pScreenPriv->pwinAllocateFB) (pScreen))
+ {
+ ErrorF ("winFinishScreenInitFB - Could not allocate framebuffer\n");
+ return FALSE;
+ }
+
+ /*
+ * Grab the number of bits that are used to represent color in each pixel.
+ */
+ if (pScreenInfo->dwBPP == 8)
+ pScreenInfo->dwDepth = 8;
+ else
+ pScreenInfo->dwDepth = winCountBits (pScreenPriv->dwRedMask)
+ + winCountBits (pScreenPriv->dwGreenMask)
+ + winCountBits (pScreenPriv->dwBlueMask);
+
+ winDebug ("winFinishScreenInitFB - Masks: %08x %08x %08x\n",
+ (unsigned int) pScreenPriv->dwRedMask,
+ (unsigned int) pScreenPriv->dwGreenMask,
+ (unsigned int) pScreenPriv->dwBlueMask);
+
+ /* Init visuals */
+ if (!(*pScreenPriv->pwinInitVisuals) (pScreen))
+ {
+ ErrorF ("winFinishScreenInitFB - winInitVisuals failed\n");
+ return FALSE;
+ }
+
+ /* Setup a local variable to point to the framebuffer */
+ pbits = pScreenInfo->pfb;
+
+ /* Apparently we need this for the render extension */
+ miSetPixmapDepths ();
+
+ /* Start fb initialization */
+ if (!fbSetupScreen (pScreen,
+ pScreenInfo->pfb,
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight,
+ monitorResolution, monitorResolution,
+ pScreenInfo->dwStride,
+ pScreenInfo->dwBPP))
+ {
+ ErrorF ("winFinishScreenInitFB - fbSetupScreen failed\n");
+ return FALSE;
+ }
+
+ /* Override default colormap routines if visual class is dynamic */
+ if (pScreenInfo->dwDepth == 8
+ && (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
+ || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL
+ && pScreenInfo->fFullScreen)
+ || (pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
+ && pScreenInfo->fFullScreen)))
+ {
+ winSetColormapFunctions (pScreen);
+
+ /*
+ * NOTE: Setting whitePixel to 255 causes Magic 7.1 to allocate its
+ * own colormap, as it cannot allocate 7 planes in the default
+ * colormap. Setting whitePixel to 1 allows Magic to get 7
+ * planes in the default colormap, so it doesn't create its
+ * own colormap. This latter situation is highly desireable,
+ * as it keeps the Magic window viewable when switching to
+ * other X clients that use the default colormap.
+ */
+ pScreen->blackPixel = 0;
+ pScreen->whitePixel = 1;
+ }
+
+ /* Place our save screen function */
+ pScreen->SaveScreen = winSaveScreen;
+
+ /* Finish fb initialization */
+ if (!fbFinishScreenInit (pScreen,
+ pScreenInfo->pfb,
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight,
+ monitorResolution, monitorResolution,
+ pScreenInfo->dwStride,
+ pScreenInfo->dwBPP))
+ {
+ ErrorF ("winFinishScreenInitFB - fbFinishScreenInit failed\n");
+ return FALSE;
+ }
+
+ /* Save a pointer to the root visual */
+ for (pVisual = pScreen->visuals;
+ pVisual->vid != pScreen->rootVisual;
+ pVisual++);
+ pScreenPriv->pRootVisual = pVisual;
+
+ /*
+ * Setup points to the block and wakeup handlers. Pass a pointer
+ * to the current screen as pWakeupdata.
+ */
+ pScreen->BlockHandler = winBlockHandler;
+ pScreen->WakeupHandler = winWakeupHandler;
+ pScreen->blockData = pScreen;
+ pScreen->wakeupData = pScreen;
+
+#ifdef RENDER
+ /* Render extension initialization, calls miPictureInit */
+ if (!fbPictureInit (pScreen, NULL, 0))
+ {
+ ErrorF ("winFinishScreenInitFB - fbPictureInit () failed\n");
+ return FALSE;
+ }
+#endif
+
+#ifdef RANDR
+ /* Initialize resize and rotate support */
+ if (!winRandRInit (pScreen))
+ {
+ ErrorF ("winFinishScreenInitFB - winRandRInit () failed\n");
+ return FALSE;
+ }
+#endif
+
+ /*
+ * Backing store support should reduce network traffic and increase
+ * performance.
+ */
+ miInitializeBackingStore (pScreen);
+
+ /* KDrive does miDCInitialize right after miInitializeBackingStore */
+ /* Setup the cursor routines */
+ winDebug ("winFinishScreenInitFB - Calling miDCInitialize ()\n");
+ miDCInitialize (pScreen, &g_winPointerCursorFuncs);
+
+ /* KDrive does winCreateDefColormap right after miDCInitialize */
+ /* Create a default colormap */
+ winDebug ("winFinishScreenInitFB - Calling winCreateDefColormap ()\n");
+ if (!winCreateDefColormap (pScreen))
+ {
+ ErrorF ("winFinishScreenInitFB - Could not create colormap\n");
+ return FALSE;
+ }
+
+ /* Initialize the shadow framebuffer layer */
+ if ((pScreenInfo->dwEngine == WIN_SERVER_SHADOW_GDI
+ || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DD
+ || pScreenInfo->dwEngine == WIN_SERVER_SHADOW_DDNL)
+#ifdef XWIN_MULTIWINDOWEXTWM
+ && !pScreenInfo->fMWExtWM
+#endif
+ )
+ {
+ winDebug ("winFinishScreenInitFB - Calling shadowSetup ()\n");
+ if (!shadowSetup(pScreen))
+ {
+ ErrorF ("winFinishScreenInitFB - shadowSetup () failed\n");
+ return FALSE;
+ }
+
+ /* Wrap CreateScreenResources so we can add the screen pixmap
+ to the Shadow framebuffer after it's been created */
+ pScreenPriv->pwinCreateScreenResources = pScreen->CreateScreenResources;
+ pScreen->CreateScreenResources = winCreateScreenResources;
+ }
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+ /* Handle multi-window external window manager mode */
+ if (pScreenInfo->fMWExtWM)
+ {
+ winDebug ("winScreenInit - MultiWindowExtWM - Calling RootlessInit\n");
+
+ RootlessInit(pScreen, &winMWExtWMProcs);
+
+ winDebug ("winScreenInit - MultiWindowExtWM - RootlessInit returned\n");
+
+ rootless_CopyBytes_threshold = 0;
+ rootless_FillBytes_threshold = 0;
+ rootless_CompositePixels_threshold = 0;
+ /* FIXME: How many? Profiling needed? */
+ rootless_CopyWindow_threshold = 1;
+
+ winWindowsWMExtensionInit ();
+ }
+#endif
+
+ /* Handle rootless mode */
+ if (pScreenInfo->fRootless)
+ {
+ /* Define the WRAP macro temporarily for local use */
+#define WRAP(a) \
+ if (pScreen->a) { \
+ pScreenPriv->a = pScreen->a; \
+ } else { \
+ ErrorF("null screen fn " #a "\n"); \
+ pScreenPriv->a = NULL; \
+ }
+
+ /* Save a pointer to each lower-level window procedure */
+ WRAP(CreateWindow);
+ WRAP(DestroyWindow);
+ WRAP(RealizeWindow);
+ WRAP(UnrealizeWindow);
+ WRAP(PositionWindow);
+ WRAP(ChangeWindowAttributes);
+ WRAP(SetShape);
+
+ /* Assign rootless window procedures to be top level procedures */
+ pScreen->CreateWindow = winCreateWindowRootless;
+ pScreen->DestroyWindow = winDestroyWindowRootless;
+ pScreen->PositionWindow = winPositionWindowRootless;
+ /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesRootless;*/
+ pScreen->RealizeWindow = winMapWindowRootless;
+ pScreen->UnrealizeWindow = winUnmapWindowRootless;
+ pScreen->SetShape = winSetShapeRootless;
+
+ /* Undefine the WRAP macro, as it is not needed elsewhere */
+#undef WRAP
+ }
+
+
+#ifdef XWIN_MULTIWINDOW
+ /* Handle multi window mode */
+ else if (pScreenInfo->fMultiWindow)
+ {
+ /* Define the WRAP macro temporarily for local use */
+#define WRAP(a) \
+ if (pScreen->a) { \
+ pScreenPriv->a = pScreen->a; \
+ } else { \
+ ErrorF("null screen fn " #a "\n"); \
+ pScreenPriv->a = NULL; \
+ }
+
+ /* Save a pointer to each lower-level window procedure */
+ WRAP(CreateWindow);
+ WRAP(DestroyWindow);
+ WRAP(RealizeWindow);
+ WRAP(UnrealizeWindow);
+ WRAP(PositionWindow);
+ WRAP(ChangeWindowAttributes);
+ WRAP(ReparentWindow);
+ WRAP(RestackWindow);
+ WRAP(ResizeWindow);
+ WRAP(MoveWindow);
+ WRAP(CopyWindow);
+ WRAP(SetShape);
+
+ /* Assign multi-window window procedures to be top level procedures */
+ pScreen->CreateWindow = winCreateWindowMultiWindow;
+ pScreen->DestroyWindow = winDestroyWindowMultiWindow;
+ pScreen->PositionWindow = winPositionWindowMultiWindow;
+ /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesMultiWindow;*/
+ pScreen->RealizeWindow = winMapWindowMultiWindow;
+ pScreen->UnrealizeWindow = winUnmapWindowMultiWindow;
+ pScreen->ReparentWindow = winReparentWindowMultiWindow;
+ pScreen->RestackWindow = winRestackWindowMultiWindow;
+ pScreen->ResizeWindow = winResizeWindowMultiWindow;
+ pScreen->MoveWindow = winMoveWindowMultiWindow;
+ pScreen->CopyWindow = winCopyWindowMultiWindow;
+ pScreen->SetShape = winSetShapeMultiWindow;
+
+ /* Undefine the WRAP macro, as it is not needed elsewhere */
+#undef WRAP
+ }
+#endif
+
+ /* Wrap either fb's or shadow's CloseScreen with our CloseScreen */
+ pScreenPriv->CloseScreen = pScreen->CloseScreen;
+ pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;
+
+#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
+ /* Create a mutex for modules in separate threads to wait for */
+ iReturn = pthread_mutex_init (&pScreenPriv->pmServerStarted, NULL);
+ if (iReturn != 0)
+ {
+ ErrorF ("winFinishScreenInitFB - pthread_mutex_init () failed: %d\n",
+ iReturn);
+ return FALSE;
+ }
+
+ /* Own the mutex for modules in separate threads */
+ iReturn = pthread_mutex_lock (&pScreenPriv->pmServerStarted);
+ if (iReturn != 0)
+ {
+ ErrorF ("winFinishScreenInitFB - pthread_mutex_lock () failed: %d\n",
+ iReturn);
+ return FALSE;
+ }
+
+ /* Set the ServerStarted flag to false */
+ pScreenPriv->fServerStarted = FALSE;
+#endif
+
+#ifdef XWIN_MULTIWINDOWEXTWM
+ pScreenPriv->fRestacking = FALSE;
+#endif
+
+#if defined(XWIN_MULTIWINDOW) || defined(XWIN_MULTIWINDOWEXTWM)
+ if (FALSE
+#ifdef XWIN_MULTIWINDOW
+ || pScreenInfo->fMultiWindow
+#endif
+#ifdef XWIN_MULTIWINDOWEXTWM
+ || pScreenInfo->fInternalWM
+#endif
+ )
+ {
+ winDebug ("winFinishScreenInitFB - Calling winInitWM.\n");
+
+ /* Initialize multi window mode */
+ if (!winInitWM (&pScreenPriv->pWMInfo,
+ &pScreenPriv->ptWMProc,
+ &pScreenPriv->ptXMsgProc,
+ &pScreenPriv->pmServerStarted,
+ pScreenInfo->dwScreen,
+ (HWND)&pScreenPriv->hwndScreen,
+#ifdef XWIN_MULTIWINDOWEXTWM
+ pScreenInfo->fInternalWM ||
+#endif
+ FALSE))
+ {
+ ErrorF ("winFinishScreenInitFB - winInitWM () failed.\n");
+ return FALSE;
+ }
+ }
+#endif
+
+ /* Tell the server that we are enabled */
+ pScreenPriv->fEnabled = TRUE;
+
+ /* Tell the server that we have a valid depth */
+ pScreenPriv->fBadDepth = FALSE;
+
+ winDebug ("winFinishScreenInitFB - returning\n");
+
+ return TRUE;
+}
+
+#ifdef XWIN_NATIVEGDI
+/* See Porting Layer Definition - p. 20 */
+
+Bool
+winFinishScreenInitNativeGDI (int index,
+ ScreenPtr pScreen,
+ int argc, char **argv)
+{
+ winScreenPriv(pScreen);
+ winScreenInfoPtr pScreenInfo = &g_ScreenInfo[index];
+ VisualPtr pVisuals = NULL;
+ DepthPtr pDepths = NULL;
+ VisualID rootVisual = 0;
+ int nVisuals = 0, nDepths = 0, nRootDepth = 0;
+
+ /* Ignore user input (mouse, keyboard) */
+ pScreenInfo->fIgnoreInput = FALSE;
+
+ /* Get device contexts for the screen and shadow bitmap */
+ pScreenPriv->hdcScreen = GetDC (pScreenPriv->hwndScreen);
+ if (pScreenPriv->hdcScreen == NULL)
+ FatalError ("winFinishScreenInitNativeGDI - Couldn't get a DC\n");
+
+ /* Init visuals */
+ if (!(*pScreenPriv->pwinInitVisuals) (pScreen))
+ {
+ ErrorF ("winFinishScreenInitNativeGDI - pwinInitVisuals failed\n");
+ return FALSE;
+ }
+
+ /* Initialize the mi visuals */
+ if (!miInitVisuals (&pVisuals, &pDepths, &nVisuals, &nDepths, &nRootDepth,
+ &rootVisual,
+ ((unsigned long)1 << (pScreenInfo->dwDepth - 1)), 8,
+ TrueColor))
+ {
+ ErrorF ("winFinishScreenInitNativeGDI - miInitVisuals () failed\n");
+ return FALSE;
+ }
+
+ /* Initialize the CloseScreen procedure pointer */
+ pScreen->CloseScreen = NULL;
+
+ /* Initialize the mi code */
+ if (!miScreenInit (pScreen,
+ NULL, /* No framebuffer */
+ pScreenInfo->dwWidth, pScreenInfo->dwHeight,
+ monitorResolution, monitorResolution,
+ pScreenInfo->dwStride,
+ nRootDepth, nDepths, pDepths, rootVisual,
+ nVisuals, pVisuals))
+ {
+ ErrorF ("winFinishScreenInitNativeGDI - miScreenInit failed\n");
+ return FALSE;
+ }
+
+ pScreen->defColormap = FakeClientID(0);
+
+ /*
+ * Register our block and wakeup handlers; these procedures
+ * process messages in our Windows message queue; specifically,
+ * they process mouse and keyboard input.
+ */
+ pScreen->BlockHandler = winBlockHandler;
+ pScreen->WakeupHandler = winWakeupHandler;
+ pScreen->blockData = pScreen;
+ pScreen->wakeupData = pScreen;
+
+ /* Place our save screen function */
+ pScreen->SaveScreen = winSaveScreen;
+
+ /* Pixmaps */
+ pScreen->CreatePixmap = winCreatePixmapNativeGDI;
+ pScreen->DestroyPixmap = winDestroyPixmapNativeGDI;
+
+ /* Other Screen Routines */
+ pScreen->QueryBestSize = winQueryBestSizeNativeGDI;
+ pScreen->SaveScreen = winSaveScreen;
+ pScreen->GetImage = miGetImage;
+ pScreen->GetSpans = winGetSpansNativeGDI;
+
+ /* Window Procedures */
+ pScreen->CreateWindow = winCreateWindowNativeGDI;
+ pScreen->DestroyWindow = winDestroyWindowNativeGDI;
+ pScreen->PositionWindow = winPositionWindowNativeGDI;
+ /*pScreen->ChangeWindowAttributes = winChangeWindowAttributesNativeGDI;*/
+ pScreen->RealizeWindow = winMapWindowNativeGDI;
+ pScreen->UnrealizeWindow = winUnmapWindowNativeGDI;
+
+ /* Paint window */
+ pScreen->CopyWindow = winCopyWindowNativeGDI;
+
+ /* Fonts */
+ pScreen->RealizeFont = winRealizeFontNativeGDI;
+ pScreen->UnrealizeFont = winUnrealizeFontNativeGDI;
+
+ /* GC */
+ pScreen->CreateGC = winCreateGCNativeGDI;
+
+ /* Colormap Routines */
+ pScreen->CreateColormap = miInitializeColormap;
+ pScreen->DestroyColormap = (DestroyColormapProcPtr) (void (*)(void)) NoopDDA;
+ pScreen->InstallColormap = miInstallColormap;
+ pScreen->UninstallColormap = miUninstallColormap;
+ pScreen->ListInstalledColormaps = miListInstalledColormaps;
+ pScreen->StoreColors = (StoreColorsProcPtr) (void (*)(void)) NoopDDA;
+ pScreen->ResolveColor = miResolveColor;
+
+ /* Bitmap */
+ pScreen->BitmapToRegion = winPixmapToRegionNativeGDI;
+
+ winDebug ("winFinishScreenInitNativeGDI - calling miDCInitialize\n");
+
+ /* Set the default white and black pixel positions */
+ pScreen->whitePixel = pScreen->blackPixel = (Pixel) 0;
+
+ /* Initialize the cursor */
+ if (!miDCInitialize (pScreen, &g_winPointerCursorFuncs))
+ {
+ ErrorF ("winFinishScreenInitNativeGDI - miDCInitialize failed\n");
+ return FALSE;
+ }
+
+ /* Create a default colormap */
+ if (!miCreateDefColormap (pScreen))
+ {
+ ErrorF ("winFinishScreenInitNativeGDI - miCreateDefColormap () "
+ "failed\n");
+ return FALSE;
+ }
+
+ winDebug ("winFinishScreenInitNativeGDI - miCreateDefColormap () "
+ "returned\n");
+
+ /* mi doesn't use a CloseScreen procedure, so no need to wrap */
+ pScreen->CloseScreen = pScreenPriv->pwinCloseScreen;
+
+ /* Tell the server that we are enabled */
+ pScreenPriv->fEnabled = TRUE;
+
+ winDebug ("winFinishScreenInitNativeGDI - Successful addition of "
+ "screen %08x\n",
+ (unsigned int) pScreen);
+
+ return TRUE;
+}
+#endif
+
+
+/* See Porting Layer Definition - p. 33 */
+static Bool
+winSaveScreen (ScreenPtr pScreen, int on)
+{
+ return TRUE;
+}
diff --git a/xorg-server/hw/xwin/winwin32rootlesswindow.c b/xorg-server/hw/xwin/winwin32rootlesswindow.c index 2b2f63010..3a49ead69 100644 --- a/xorg-server/hw/xwin/winwin32rootlesswindow.c +++ b/xorg-server/hw/xwin/winwin32rootlesswindow.c @@ -164,7 +164,7 @@ winMWExtWMUpdateIcon (Window id) WindowPtr pWin; HICON hIcon, hiconOld; - pWin = (WindowPtr) LookupIDByType (id, RT_WINDOW); + dixLookupResourceByType((pointer) &pWin, id, RT_WINDOW, NullClient, DixUnknownAccess); hIcon = winOverrideIcon ((unsigned long)pWin); if (!hIcon) diff --git a/xorg-server/hw/xwin/winwindowswm.c b/xorg-server/hw/xwin/winwindowswm.c index 73776ba5f..d1b405683 100644 --- a/xorg-server/hw/xwin/winwindowswm.c +++ b/xorg-server/hw/xwin/winwindowswm.c @@ -1,629 +1,630 @@ -/* WindowsWM extension is based on AppleWM extension */ -/************************************************************************** - -Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved. -Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -#ifdef HAVE_XWIN_CONFIG_H -#include <xwin-config.h> -#endif -#include "win.h" - -#include "misc.h" -#include "dixstruct.h" -#include "extnsionst.h" -#include "colormapst.h" -#include "cursorstr.h" -#include "scrnintstr.h" -#include "servermd.h" -#include "swaprep.h" -#define _WINDOWSWM_SERVER_ -#include <X11/extensions/windowswmstr.h> -#include "protocol-versions.h" - -static int WMErrorBase; - -static DISPATCH_PROC(ProcWindowsWMDispatch); -static DISPATCH_PROC(SProcWindowsWMDispatch); - -static unsigned char WMReqCode = 0; -static int WMEventBase = 0; - -static RESTYPE ClientType, eventResourceType; /* resource types for event masks */ -static XID eventResource; - -/* Currently selected events */ -static unsigned int eventMask = 0; - -static int WMFreeClient (pointer data, XID id); -static int WMFreeEvents (pointer data, XID id); -static void SNotifyEvent(xWindowsWMNotifyEvent *from, xWindowsWMNotifyEvent *to); - -typedef struct _WMEvent *WMEventPtr; -typedef struct _WMEvent { - WMEventPtr next; - ClientPtr client; - XID clientResource; - unsigned int mask; -} WMEventRec; - -static inline BoxRec -make_box (int x, int y, int w, int h) -{ - BoxRec r; - r.x1 = x; - r.y1 = y; - r.x2 = x + w; - r.y2 = y + h; - return r; -} - -void -winWindowsWMExtensionInit () -{ - ExtensionEntry* extEntry; - - ClientType = CreateNewResourceType(WMFreeClient); - eventResourceType = CreateNewResourceType(WMFreeEvents); - eventResource = FakeClientID(0); - - if (ClientType && eventResourceType && - (extEntry = AddExtension(WINDOWSWMNAME, - WindowsWMNumberEvents, - WindowsWMNumberErrors, - ProcWindowsWMDispatch, - SProcWindowsWMDispatch, - NULL, - StandardMinorOpcode))) - { - WMReqCode = (unsigned char)extEntry->base; - WMErrorBase = extEntry->errorBase; - WMEventBase = extEntry->eventBase; - EventSwapVector[WMEventBase] = (EventSwapPtr) SNotifyEvent; - } -} - -static int -ProcWindowsWMQueryVersion(register ClientPtr client) -{ - xWindowsWMQueryVersionReply rep; - register int n; - - REQUEST_SIZE_MATCH(xWindowsWMQueryVersionReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - rep.majorVersion = SERVER_WINDOWSWM_MAJOR_VERSION; - rep.minorVersion = SERVER_WINDOWSWM_MINOR_VERSION; - rep.patchVersion = SERVER_WINDOWSWM_PATCH_VERSION; - if (client->swapped) - { - swaps(&rep.sequenceNumber, n); - swapl(&rep.length, n); - } - WriteToClient(client, sizeof(xWindowsWMQueryVersionReply), (char *)&rep); - return (client->noClientException); -} - - -/* events */ - -static inline void -updateEventMask (WMEventPtr *pHead) -{ - WMEventPtr pCur; - - eventMask = 0; - for (pCur = *pHead; pCur != NULL; pCur = pCur->next) - eventMask |= pCur->mask; -} - -/*ARGSUSED*/ -static int -WMFreeClient (pointer data, XID id) -{ - WMEventPtr pEvent; - WMEventPtr *pHead, pCur, pPrev; - - pEvent = (WMEventPtr) data; - pHead = (WMEventPtr *) LookupIDByType(eventResource, eventResourceType); - if (pHead) - { - pPrev = 0; - for (pCur = *pHead; pCur && pCur != pEvent; pCur=pCur->next) - pPrev = pCur; - if (pCur) - { - if (pPrev) - pPrev->next = pEvent->next; - else - *pHead = pEvent->next; - } - updateEventMask (pHead); - } - xfree ((pointer) pEvent); - return 1; -} - -/*ARGSUSED*/ -static int -WMFreeEvents (pointer data, XID id) -{ - WMEventPtr *pHead, pCur, pNext; - - pHead = (WMEventPtr *) data; - for (pCur = *pHead; pCur; pCur = pNext) - { - pNext = pCur->next; - FreeResource (pCur->clientResource, ClientType); - xfree ((pointer) pCur); - } - xfree ((pointer) pHead); - eventMask = 0; - return 1; -} - -static int -ProcWindowsWMSelectInput (register ClientPtr client) -{ - REQUEST(xWindowsWMSelectInputReq); - WMEventPtr pEvent, pNewEvent, *pHead; - XID clientResource; - - REQUEST_SIZE_MATCH (xWindowsWMSelectInputReq); - pHead = (WMEventPtr *)SecurityLookupIDByType(client, eventResource, - eventResourceType, DixWriteAccess); - if (stuff->mask != 0) - { - if (pHead) - { - /* check for existing entry. */ - for (pEvent = *pHead; pEvent; pEvent = pEvent->next) - { - if (pEvent->client == client) - { - pEvent->mask = stuff->mask; - updateEventMask (pHead); - return Success; - } - } - } - - /* build the entry */ - pNewEvent = (WMEventPtr) xalloc (sizeof (WMEventRec)); - if (!pNewEvent) - return BadAlloc; - pNewEvent->next = 0; - pNewEvent->client = client; - pNewEvent->mask = stuff->mask; - /* - * add a resource that will be deleted when - * the client goes away - */ - clientResource = FakeClientID (client->index); - pNewEvent->clientResource = clientResource; - if (!AddResource (clientResource, ClientType, (pointer)pNewEvent)) - return BadAlloc; - /* - * create a resource to contain a pointer to the list - * of clients selecting input. This must be indirect as - * the list may be arbitrarily rearranged which cannot be - * done through the resource database. - */ - if (!pHead) - { - pHead = (WMEventPtr *) xalloc (sizeof (WMEventPtr)); - if (!pHead || - !AddResource (eventResource, eventResourceType, (pointer)pHead)) - { - FreeResource (clientResource, RT_NONE); - return BadAlloc; - } - *pHead = 0; - } - pNewEvent->next = *pHead; - *pHead = pNewEvent; - updateEventMask (pHead); - } - else if (stuff->mask == 0) - { - /* delete the interest */ - if (pHead) - { - pNewEvent = 0; - for (pEvent = *pHead; pEvent; pEvent = pEvent->next) - { - if (pEvent->client == client) - break; - pNewEvent = pEvent; - } - if (pEvent) - { - FreeResource (pEvent->clientResource, ClientType); - if (pNewEvent) - pNewEvent->next = pEvent->next; - else - *pHead = pEvent->next; - xfree (pEvent); - updateEventMask (pHead); - } - } - } - else - { - client->errorValue = stuff->mask; - return BadValue; - } - return Success; -} - -/* - * deliver the event - */ - -void -winWindowsWMSendEvent (int type, unsigned int mask, int which, int arg, - Window window, int x, int y, int w, int h) -{ - WMEventPtr *pHead, pEvent; - ClientPtr client; - xWindowsWMNotifyEvent se; - winDebug ("winWindowsWMSendEvent %d %d %d %d, %d %d - %d %d\n", - type, mask, which, arg, x, y, w, h); - pHead = (WMEventPtr *) LookupIDByType(eventResource, eventResourceType); - if (!pHead) - return; - for (pEvent = *pHead; pEvent; pEvent = pEvent->next) - { - client = pEvent->client; - winDebug ("winWindowsWMSendEvent - x%08x\n", (int) client); - if ((pEvent->mask & mask) == 0 - || client == serverClient || client->clientGone) - { - continue; - } - winDebug ("winWindowsWMSendEvent - send\n"); - - se.type = type + WMEventBase; - se.kind = which; - se.window = window; - se.arg = arg; - se.x = x; - se.y = y; - se.w = w; - se.h = h; - se.sequenceNumber = client->sequence; - se.time = currentTime.milliseconds; - WriteEventsToClient (client, 1, (xEvent *) &se); - } -} - -/* Safe to call from any thread. */ -unsigned int -WindowsWMSelectedEvents (void) -{ - return eventMask; -} - - -/* general utility functions */ - -static int -ProcWindowsWMDisableUpdate (register ClientPtr client) -{ - REQUEST_SIZE_MATCH(xWindowsWMDisableUpdateReq); - - //winDisableUpdate(); - - return (client->noClientException); -} - -static int -ProcWindowsWMReenableUpdate (register ClientPtr client) -{ - REQUEST_SIZE_MATCH(xWindowsWMReenableUpdateReq); - - //winEnableUpdate(); - - return (client->noClientException); -} - - -/* window functions */ - -static int -ProcWindowsWMSetFrontProcess (register ClientPtr client) -{ - REQUEST_SIZE_MATCH(xWindowsWMSetFrontProcessReq); - - //QuartzMessageMainThread(kWindowsSetFrontProcess, NULL, 0); - - return (client->noClientException); -} - - -/* frame functions */ - -static int -ProcWindowsWMFrameGetRect (register ClientPtr client) -{ - xWindowsWMFrameGetRectReply rep; - BoxRec ir; - RECT rcNew; - REQUEST(xWindowsWMFrameGetRectReq); - - winDebug ("ProcWindowsWMFrameGetRect %d %d\n", - (sizeof(xWindowsWMFrameGetRectReq) >> 2), (int) client->req_len); - - REQUEST_SIZE_MATCH(xWindowsWMFrameGetRectReq); - rep.type = X_Reply; - rep.length = 0; - rep.sequenceNumber = client->sequence; - - ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih); - - if (stuff->frame_rect != 0) - { - ErrorF ("ProcWindowsWMFrameGetRect - stuff->frame_rect != 0\n"); - return BadValue; - } - - /* Store the origin, height, and width in a rectangle structure */ - SetRect (&rcNew, stuff->ix, stuff->iy, - stuff->ix + stuff->iw, stuff->iy + stuff->ih); - - winDebug ("ProcWindowsWMFrameGetRect - %d %d %d %d\n", - stuff->ix, stuff->iy, stuff->ix + stuff->iw, stuff->iy + stuff->ih); - - /* - * Calculate the required size of the Windows window rectangle, - * given the size of the Windows window client area. - */ - AdjustWindowRectEx (&rcNew, stuff->frame_style, FALSE, stuff->frame_style_ex); - rep.x = rcNew.left; - rep.y = rcNew.top; - rep.w = rcNew.right - rcNew.left; - rep.h = rcNew.bottom - rcNew.top; - winDebug ("ProcWindowsWMFrameGetRect - %d %d %d %d\n", - rep.x, rep.y, rep.w, rep.h); - - WriteToClient(client, sizeof(xWindowsWMFrameGetRectReply), (char *)&rep); - return (client->noClientException); -} - - -static int -ProcWindowsWMFrameDraw (register ClientPtr client) -{ - REQUEST(xWindowsWMFrameDrawReq); - WindowPtr pWin; - win32RootlessWindowPtr pRLWinPriv; - RECT rcNew; - int nCmdShow, rc; - RegionRec newShape; - ScreenPtr pScreen; - - REQUEST_SIZE_MATCH (xWindowsWMFrameDrawReq); - - winDebug ("ProcWindowsWMFrameDraw\n"); - - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - if (rc != Success) - return rc; - - winDebug ("ProcWindowsWMFrameDraw - Window found\n"); - - pRLWinPriv = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, TRUE); - if (pRLWinPriv == 0) return BadWindow; - - winDebug ("ProcWindowsWMFrameDraw - HWND 0x%08x 0x%08x 0x%08x\n", - (int) pRLWinPriv->hWnd, (int) stuff->frame_style, - (int) stuff->frame_style_ex); - winDebug ("ProcWindowsWMFrameDraw - %d %d %d %d\n", - stuff->ix, stuff->iy, stuff->iw, stuff->ih); - - /* Store the origin, height, and width in a rectangle structure */ - SetRect (&rcNew, stuff->ix, stuff->iy, - stuff->ix + stuff->iw, stuff->iy + stuff->ih); - - /* - * Calculate the required size of the Windows window rectangle, - * given the size of the Windows window client area. - */ - AdjustWindowRectEx (&rcNew, stuff->frame_style, FALSE, stuff->frame_style_ex); - - /* Set the window extended style flags */ - if (!SetWindowLongPtr (pRLWinPriv->hWnd, GWL_EXSTYLE, stuff->frame_style_ex)) - { - return BadValue; - } - - /* Set the window standard style flags */ - if (!SetWindowLongPtr (pRLWinPriv->hWnd, GWL_STYLE, stuff->frame_style)) - { - return BadValue; - } - - /* Flush the window style */ - if (!SetWindowPos (pRLWinPriv->hWnd, NULL, - rcNew.left, rcNew.top, - rcNew.right - rcNew.left, rcNew.bottom - rcNew.top, - SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE)) - { - return BadValue; - } - if (!IsWindowVisible(pRLWinPriv->hWnd)) - nCmdShow = SW_HIDE; - else - nCmdShow = SW_SHOWNA; - - ShowWindow (pRLWinPriv->hWnd, nCmdShow); - - winMWExtWMUpdateIcon (pWin->drawable.id); - - if (wBoundingShape(pWin) != NULL) - { - pScreen = pWin->drawable.pScreen; - /* wBoundingShape is relative to *inner* origin of window. - Translate by borderWidth to get the outside-relative position. */ - - REGION_NULL(pScreen, &newShape); - REGION_COPY(pScreen, &newShape, wBoundingShape(pWin)); - REGION_TRANSLATE(pScreen, &newShape, pWin->borderWidth, pWin->borderWidth); - winMWExtWMReshapeFrame (pRLWinPriv, &newShape); - REGION_UNINIT(pScreen, &newShape); - } - winDebug ("ProcWindowsWMFrameDraw - done\n"); - - return (client->noClientException); -} - -static int -ProcWindowsWMFrameSetTitle( - register ClientPtr client - ) -{ - unsigned int title_length, title_max; - unsigned char *title_bytes; - REQUEST(xWindowsWMFrameSetTitleReq); - WindowPtr pWin; - win32RootlessWindowPtr pRLWinPriv; - int rc; - - winDebug ("ProcWindowsWMFrameSetTitle\n"); - - REQUEST_AT_LEAST_SIZE(xWindowsWMFrameSetTitleReq); - - rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess); - if (rc != Success) - return rc; - winDebug ("ProcWindowsWMFrameSetTitle - Window found\n"); - - title_length = stuff->title_length; - title_max = (stuff->length << 2) - sizeof(xWindowsWMFrameSetTitleReq); - - if (title_max < title_length) - return BadValue; - - winDebug ("ProcWindowsWMFrameSetTitle - length is valid\n"); - - title_bytes = malloc (title_length+1); - strncpy (title_bytes, (unsigned char *) &stuff[1], title_length); - title_bytes[title_length] = '\0'; - - pRLWinPriv = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, FALSE); - - if (pRLWinPriv == 0) - { - free (title_bytes); - return BadWindow; - } - - /* Flush the window style */ - SetWindowText (pRLWinPriv->hWnd, title_bytes); - - free (title_bytes); - - winDebug ("ProcWindowsWMFrameSetTitle - done\n"); - - return (client->noClientException); -} - - -/* dispatch */ - -static int -ProcWindowsWMDispatch (register ClientPtr client) -{ - REQUEST(xReq); - - switch (stuff->data) - { - case X_WindowsWMQueryVersion: - return ProcWindowsWMQueryVersion(client); - } - - if (!LocalClient(client)) - return WMErrorBase + WindowsWMClientNotLocal; - - switch (stuff->data) - { - case X_WindowsWMSelectInput: - return ProcWindowsWMSelectInput(client); - case X_WindowsWMDisableUpdate: - return ProcWindowsWMDisableUpdate(client); - case X_WindowsWMReenableUpdate: - return ProcWindowsWMReenableUpdate(client); - case X_WindowsWMSetFrontProcess: - return ProcWindowsWMSetFrontProcess(client); - case X_WindowsWMFrameGetRect: - return ProcWindowsWMFrameGetRect(client); - case X_WindowsWMFrameDraw: - return ProcWindowsWMFrameDraw(client); - case X_WindowsWMFrameSetTitle: - return ProcWindowsWMFrameSetTitle(client); - default: - return BadRequest; - } -} - -static void -SNotifyEvent (xWindowsWMNotifyEvent *from, xWindowsWMNotifyEvent *to) -{ - to->type = from->type; - to->kind = from->kind; - cpswaps (from->sequenceNumber, to->sequenceNumber); - cpswapl (from->window, to->window); - cpswapl (from->time, to->time); - cpswapl (from->arg, to->arg); -} - -static int -SProcWindowsWMQueryVersion (register ClientPtr client) -{ - register int n; - REQUEST(xWindowsWMQueryVersionReq); - swaps(&stuff->length, n); - return ProcWindowsWMQueryVersion(client); -} - -static int -SProcWindowsWMDispatch (register ClientPtr client) -{ - REQUEST(xReq); - - /* It is bound to be non-local when there is byte swapping */ - if (!LocalClient(client)) - return WMErrorBase + WindowsWMClientNotLocal; - - /* only local clients are allowed WM access */ - switch (stuff->data) - { - case X_WindowsWMQueryVersion: - return SProcWindowsWMQueryVersion(client); - default: - return BadRequest; - } -} +/* WindowsWM extension is based on AppleWM extension */
+/**************************************************************************
+
+Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
+Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sub license, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice (including the
+next paragraph) shall be included in all copies or substantial portions
+of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
+ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+**************************************************************************/
+
+#ifdef HAVE_XWIN_CONFIG_H
+#include <xwin-config.h>
+#endif
+#include "win.h"
+
+#include "misc.h"
+#include "dixstruct.h"
+#include "extnsionst.h"
+#include "colormapst.h"
+#include "cursorstr.h"
+#include "scrnintstr.h"
+#include "servermd.h"
+#include "swaprep.h"
+#define _WINDOWSWM_SERVER_
+#include <X11/extensions/windowswmstr.h>
+#include "protocol-versions.h"
+
+static int WMErrorBase;
+
+static DISPATCH_PROC(ProcWindowsWMDispatch);
+static DISPATCH_PROC(SProcWindowsWMDispatch);
+
+static unsigned char WMReqCode = 0;
+static int WMEventBase = 0;
+
+static RESTYPE ClientType, eventResourceType; /* resource types for event masks */
+static XID eventResource;
+
+/* Currently selected events */
+static unsigned int eventMask = 0;
+
+static int WMFreeClient (pointer data, XID id);
+static int WMFreeEvents (pointer data, XID id);
+static void SNotifyEvent(xWindowsWMNotifyEvent *from, xWindowsWMNotifyEvent *to);
+
+typedef struct _WMEvent *WMEventPtr;
+typedef struct _WMEvent {
+ WMEventPtr next;
+ ClientPtr client;
+ XID clientResource;
+ unsigned int mask;
+} WMEventRec;
+
+static inline BoxRec
+make_box (int x, int y, int w, int h)
+{
+ BoxRec r;
+ r.x1 = x;
+ r.y1 = y;
+ r.x2 = x + w;
+ r.y2 = y + h;
+ return r;
+}
+
+void
+winWindowsWMExtensionInit ()
+{
+ ExtensionEntry* extEntry;
+
+ ClientType = CreateNewResourceType(WMFreeClient);
+ eventResourceType = CreateNewResourceType(WMFreeEvents);
+ eventResource = FakeClientID(0);
+
+ if (ClientType && eventResourceType &&
+ (extEntry = AddExtension(WINDOWSWMNAME,
+ WindowsWMNumberEvents,
+ WindowsWMNumberErrors,
+ ProcWindowsWMDispatch,
+ SProcWindowsWMDispatch,
+ NULL,
+ StandardMinorOpcode)))
+ {
+ WMReqCode = (unsigned char)extEntry->base;
+ WMErrorBase = extEntry->errorBase;
+ WMEventBase = extEntry->eventBase;
+ EventSwapVector[WMEventBase] = (EventSwapPtr) SNotifyEvent;
+ }
+}
+
+static int
+ProcWindowsWMQueryVersion(register ClientPtr client)
+{
+ xWindowsWMQueryVersionReply rep;
+ register int n;
+
+ REQUEST_SIZE_MATCH(xWindowsWMQueryVersionReq);
+ rep.type = X_Reply;
+ rep.length = 0;
+ rep.sequenceNumber = client->sequence;
+ rep.majorVersion = SERVER_WINDOWSWM_MAJOR_VERSION;
+ rep.minorVersion = SERVER_WINDOWSWM_MINOR_VERSION;
+ rep.patchVersion = SERVER_WINDOWSWM_PATCH_VERSION;
+ if (client->swapped)
+ {
+ swaps(&rep.sequenceNumber, n);
+ swapl(&rep.length, n);
+ }
+ WriteToClient(client, sizeof(xWindowsWMQueryVersionReply), (char *)&rep);
+ return (client->noClientException);
+}
+
+
+/* events */
+
+static inline void
+updateEventMask (WMEventPtr *pHead)
+{
+ WMEventPtr pCur;
+
+ eventMask = 0;
+ for (pCur = *pHead; pCur != NULL; pCur = pCur->next)
+ eventMask |= pCur->mask;
+}
+
+/*ARGSUSED*/
+static int
+WMFreeClient (pointer data, XID id)
+{
+ WMEventPtr pEvent;
+ WMEventPtr *pHead, pCur, pPrev;
+
+ pEvent = (WMEventPtr) data;
+ dixLookupResourceByType((pointer) &pHead, eventResource, eventResourceType,
+ NullClient, DixUnknownAccess);
+ if (pHead)
+ {
+ pPrev = 0;
+ for (pCur = *pHead; pCur && pCur != pEvent; pCur=pCur->next)
+ pPrev = pCur;
+ if (pCur)
+ {
+ if (pPrev)
+ pPrev->next = pEvent->next;
+ else
+ *pHead = pEvent->next;
+ }
+ updateEventMask (pHead);
+ }
+ xfree ((pointer) pEvent);
+ return 1;
+}
+
+/*ARGSUSED*/
+static int
+WMFreeEvents (pointer data, XID id)
+{
+ WMEventPtr *pHead, pCur, pNext;
+
+ pHead = (WMEventPtr *) data;
+ for (pCur = *pHead; pCur; pCur = pNext)
+ {
+ pNext = pCur->next;
+ FreeResource (pCur->clientResource, ClientType);
+ xfree ((pointer) pCur);
+ }
+ xfree ((pointer) pHead);
+ eventMask = 0;
+ return 1;
+}
+
+static int
+ProcWindowsWMSelectInput (register ClientPtr client)
+{
+ REQUEST(xWindowsWMSelectInputReq);
+ WMEventPtr pEvent, pNewEvent, *pHead;
+ XID clientResource;
+
+ REQUEST_SIZE_MATCH (xWindowsWMSelectInputReq);
+ dixLookupResourceByType((pointer) &pHead, eventResource, eventResourceType, client, DixWriteAccess);
+ if (stuff->mask != 0)
+ {
+ if (pHead)
+ {
+ /* check for existing entry. */
+ for (pEvent = *pHead; pEvent; pEvent = pEvent->next)
+ {
+ if (pEvent->client == client)
+ {
+ pEvent->mask = stuff->mask;
+ updateEventMask (pHead);
+ return Success;
+ }
+ }
+ }
+
+ /* build the entry */
+ pNewEvent = (WMEventPtr) xalloc (sizeof (WMEventRec));
+ if (!pNewEvent)
+ return BadAlloc;
+ pNewEvent->next = 0;
+ pNewEvent->client = client;
+ pNewEvent->mask = stuff->mask;
+ /*
+ * add a resource that will be deleted when
+ * the client goes away
+ */
+ clientResource = FakeClientID (client->index);
+ pNewEvent->clientResource = clientResource;
+ if (!AddResource (clientResource, ClientType, (pointer)pNewEvent))
+ return BadAlloc;
+ /*
+ * create a resource to contain a pointer to the list
+ * of clients selecting input. This must be indirect as
+ * the list may be arbitrarily rearranged which cannot be
+ * done through the resource database.
+ */
+ if (!pHead)
+ {
+ pHead = (WMEventPtr *) xalloc (sizeof (WMEventPtr));
+ if (!pHead ||
+ !AddResource (eventResource, eventResourceType, (pointer)pHead))
+ {
+ FreeResource (clientResource, RT_NONE);
+ return BadAlloc;
+ }
+ *pHead = 0;
+ }
+ pNewEvent->next = *pHead;
+ *pHead = pNewEvent;
+ updateEventMask (pHead);
+ }
+ else if (stuff->mask == 0)
+ {
+ /* delete the interest */
+ if (pHead)
+ {
+ pNewEvent = 0;
+ for (pEvent = *pHead; pEvent; pEvent = pEvent->next)
+ {
+ if (pEvent->client == client)
+ break;
+ pNewEvent = pEvent;
+ }
+ if (pEvent)
+ {
+ FreeResource (pEvent->clientResource, ClientType);
+ if (pNewEvent)
+ pNewEvent->next = pEvent->next;
+ else
+ *pHead = pEvent->next;
+ xfree (pEvent);
+ updateEventMask (pHead);
+ }
+ }
+ }
+ else
+ {
+ client->errorValue = stuff->mask;
+ return BadValue;
+ }
+ return Success;
+}
+
+/*
+ * deliver the event
+ */
+
+void
+winWindowsWMSendEvent (int type, unsigned int mask, int which, int arg,
+ Window window, int x, int y, int w, int h)
+{
+ WMEventPtr *pHead, pEvent;
+ ClientPtr client;
+ xWindowsWMNotifyEvent se;
+ winDebug ("winWindowsWMSendEvent %d %d %d %d, %d %d - %d %d\n",
+ type, mask, which, arg, x, y, w, h);
+ dixLookupResourceByType((pointer) &pHead, eventResource, eventResourceType,
+ NullClient, DixUnknownAccess);
+ if (!pHead)
+ return;
+ for (pEvent = *pHead; pEvent; pEvent = pEvent->next)
+ {
+ client = pEvent->client;
+ winDebug ("winWindowsWMSendEvent - x%08x\n", (int) client);
+ if ((pEvent->mask & mask) == 0
+ || client == serverClient || client->clientGone)
+ {
+ continue;
+ }
+ winDebug ("winWindowsWMSendEvent - send\n");
+
+ se.type = type + WMEventBase;
+ se.kind = which;
+ se.window = window;
+ se.arg = arg;
+ se.x = x;
+ se.y = y;
+ se.w = w;
+ se.h = h;
+ se.sequenceNumber = client->sequence;
+ se.time = currentTime.milliseconds;
+ WriteEventsToClient (client, 1, (xEvent *) &se);
+ }
+}
+
+/* Safe to call from any thread. */
+unsigned int
+WindowsWMSelectedEvents (void)
+{
+ return eventMask;
+}
+
+
+/* general utility functions */
+
+static int
+ProcWindowsWMDisableUpdate (register ClientPtr client)
+{
+ REQUEST_SIZE_MATCH(xWindowsWMDisableUpdateReq);
+
+ //winDisableUpdate();
+
+ return (client->noClientException);
+}
+
+static int
+ProcWindowsWMReenableUpdate (register ClientPtr client)
+{
+ REQUEST_SIZE_MATCH(xWindowsWMReenableUpdateReq);
+
+ //winEnableUpdate();
+
+ return (client->noClientException);
+}
+
+
+/* window functions */
+
+static int
+ProcWindowsWMSetFrontProcess (register ClientPtr client)
+{
+ REQUEST_SIZE_MATCH(xWindowsWMSetFrontProcessReq);
+
+ //QuartzMessageMainThread(kWindowsSetFrontProcess, NULL, 0);
+
+ return (client->noClientException);
+}
+
+
+/* frame functions */
+
+static int
+ProcWindowsWMFrameGetRect (register ClientPtr client)
+{
+ xWindowsWMFrameGetRectReply rep;
+ BoxRec ir;
+ RECT rcNew;
+ REQUEST(xWindowsWMFrameGetRectReq);
+
+ winDebug ("ProcWindowsWMFrameGetRect %d %d\n",
+ (sizeof(xWindowsWMFrameGetRectReq) >> 2), (int) client->req_len);
+
+ REQUEST_SIZE_MATCH(xWindowsWMFrameGetRectReq);
+ rep.type = X_Reply;
+ rep.length = 0;
+ rep.sequenceNumber = client->sequence;
+
+ ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih);
+
+ if (stuff->frame_rect != 0)
+ {
+ ErrorF ("ProcWindowsWMFrameGetRect - stuff->frame_rect != 0\n");
+ return BadValue;
+ }
+
+ /* Store the origin, height, and width in a rectangle structure */
+ SetRect (&rcNew, stuff->ix, stuff->iy,
+ stuff->ix + stuff->iw, stuff->iy + stuff->ih);
+
+ winDebug ("ProcWindowsWMFrameGetRect - %d %d %d %d\n",
+ stuff->ix, stuff->iy, stuff->ix + stuff->iw, stuff->iy + stuff->ih);
+
+ /*
+ * Calculate the required size of the Windows window rectangle,
+ * given the size of the Windows window client area.
+ */
+ AdjustWindowRectEx (&rcNew, stuff->frame_style, FALSE, stuff->frame_style_ex);
+ rep.x = rcNew.left;
+ rep.y = rcNew.top;
+ rep.w = rcNew.right - rcNew.left;
+ rep.h = rcNew.bottom - rcNew.top;
+ winDebug ("ProcWindowsWMFrameGetRect - %d %d %d %d\n",
+ rep.x, rep.y, rep.w, rep.h);
+
+ WriteToClient(client, sizeof(xWindowsWMFrameGetRectReply), (char *)&rep);
+ return (client->noClientException);
+}
+
+
+static int
+ProcWindowsWMFrameDraw (register ClientPtr client)
+{
+ REQUEST(xWindowsWMFrameDrawReq);
+ WindowPtr pWin;
+ win32RootlessWindowPtr pRLWinPriv;
+ RECT rcNew;
+ int nCmdShow, rc;
+ RegionRec newShape;
+ ScreenPtr pScreen;
+
+ REQUEST_SIZE_MATCH (xWindowsWMFrameDrawReq);
+
+ winDebug ("ProcWindowsWMFrameDraw\n");
+
+ rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+ if (rc != Success)
+ return rc;
+
+ winDebug ("ProcWindowsWMFrameDraw - Window found\n");
+
+ pRLWinPriv = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, TRUE);
+ if (pRLWinPriv == 0) return BadWindow;
+
+ winDebug ("ProcWindowsWMFrameDraw - HWND 0x%08x 0x%08x 0x%08x\n",
+ (int) pRLWinPriv->hWnd, (int) stuff->frame_style,
+ (int) stuff->frame_style_ex);
+ winDebug ("ProcWindowsWMFrameDraw - %d %d %d %d\n",
+ stuff->ix, stuff->iy, stuff->iw, stuff->ih);
+
+ /* Store the origin, height, and width in a rectangle structure */
+ SetRect (&rcNew, stuff->ix, stuff->iy,
+ stuff->ix + stuff->iw, stuff->iy + stuff->ih);
+
+ /*
+ * Calculate the required size of the Windows window rectangle,
+ * given the size of the Windows window client area.
+ */
+ AdjustWindowRectEx (&rcNew, stuff->frame_style, FALSE, stuff->frame_style_ex);
+
+ /* Set the window extended style flags */
+ if (!SetWindowLongPtr (pRLWinPriv->hWnd, GWL_EXSTYLE, stuff->frame_style_ex))
+ {
+ return BadValue;
+ }
+
+ /* Set the window standard style flags */
+ if (!SetWindowLongPtr (pRLWinPriv->hWnd, GWL_STYLE, stuff->frame_style))
+ {
+ return BadValue;
+ }
+
+ /* Flush the window style */
+ if (!SetWindowPos (pRLWinPriv->hWnd, NULL,
+ rcNew.left, rcNew.top,
+ rcNew.right - rcNew.left, rcNew.bottom - rcNew.top,
+ SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE))
+ {
+ return BadValue;
+ }
+ if (!IsWindowVisible(pRLWinPriv->hWnd))
+ nCmdShow = SW_HIDE;
+ else
+ nCmdShow = SW_SHOWNA;
+
+ ShowWindow (pRLWinPriv->hWnd, nCmdShow);
+
+ winMWExtWMUpdateIcon (pWin->drawable.id);
+
+ if (wBoundingShape(pWin) != NULL)
+ {
+ pScreen = pWin->drawable.pScreen;
+ /* wBoundingShape is relative to *inner* origin of window.
+ Translate by borderWidth to get the outside-relative position. */
+
+ REGION_NULL(pScreen, &newShape);
+ REGION_COPY(pScreen, &newShape, wBoundingShape(pWin));
+ REGION_TRANSLATE(pScreen, &newShape, pWin->borderWidth, pWin->borderWidth);
+ winMWExtWMReshapeFrame (pRLWinPriv, &newShape);
+ REGION_UNINIT(pScreen, &newShape);
+ }
+ winDebug ("ProcWindowsWMFrameDraw - done\n");
+
+ return (client->noClientException);
+}
+
+static int
+ProcWindowsWMFrameSetTitle(
+ register ClientPtr client
+ )
+{
+ unsigned int title_length, title_max;
+ unsigned char *title_bytes;
+ REQUEST(xWindowsWMFrameSetTitleReq);
+ WindowPtr pWin;
+ win32RootlessWindowPtr pRLWinPriv;
+ int rc;
+
+ winDebug ("ProcWindowsWMFrameSetTitle\n");
+
+ REQUEST_AT_LEAST_SIZE(xWindowsWMFrameSetTitleReq);
+
+ rc = dixLookupWindow(&pWin, stuff->window, client, DixReadAccess);
+ if (rc != Success)
+ return rc;
+ winDebug ("ProcWindowsWMFrameSetTitle - Window found\n");
+
+ title_length = stuff->title_length;
+ title_max = (stuff->length << 2) - sizeof(xWindowsWMFrameSetTitleReq);
+
+ if (title_max < title_length)
+ return BadValue;
+
+ winDebug ("ProcWindowsWMFrameSetTitle - length is valid\n");
+
+ title_bytes = malloc (title_length+1);
+ strncpy (title_bytes, (unsigned char *) &stuff[1], title_length);
+ title_bytes[title_length] = '\0';
+
+ pRLWinPriv = (win32RootlessWindowPtr) RootlessFrameForWindow (pWin, FALSE);
+
+ if (pRLWinPriv == 0)
+ {
+ free (title_bytes);
+ return BadWindow;
+ }
+
+ /* Flush the window style */
+ SetWindowText (pRLWinPriv->hWnd, title_bytes);
+
+ free (title_bytes);
+
+ winDebug ("ProcWindowsWMFrameSetTitle - done\n");
+
+ return (client->noClientException);
+}
+
+
+/* dispatch */
+
+static int
+ProcWindowsWMDispatch (register ClientPtr client)
+{
+ REQUEST(xReq);
+
+ switch (stuff->data)
+ {
+ case X_WindowsWMQueryVersion:
+ return ProcWindowsWMQueryVersion(client);
+ }
+
+ if (!LocalClient(client))
+ return WMErrorBase + WindowsWMClientNotLocal;
+
+ switch (stuff->data)
+ {
+ case X_WindowsWMSelectInput:
+ return ProcWindowsWMSelectInput(client);
+ case X_WindowsWMDisableUpdate:
+ return ProcWindowsWMDisableUpdate(client);
+ case X_WindowsWMReenableUpdate:
+ return ProcWindowsWMReenableUpdate(client);
+ case X_WindowsWMSetFrontProcess:
+ return ProcWindowsWMSetFrontProcess(client);
+ case X_WindowsWMFrameGetRect:
+ return ProcWindowsWMFrameGetRect(client);
+ case X_WindowsWMFrameDraw:
+ return ProcWindowsWMFrameDraw(client);
+ case X_WindowsWMFrameSetTitle:
+ return ProcWindowsWMFrameSetTitle(client);
+ default:
+ return BadRequest;
+ }
+}
+
+static void
+SNotifyEvent (xWindowsWMNotifyEvent *from, xWindowsWMNotifyEvent *to)
+{
+ to->type = from->type;
+ to->kind = from->kind;
+ cpswaps (from->sequenceNumber, to->sequenceNumber);
+ cpswapl (from->window, to->window);
+ cpswapl (from->time, to->time);
+ cpswapl (from->arg, to->arg);
+}
+
+static int
+SProcWindowsWMQueryVersion (register ClientPtr client)
+{
+ register int n;
+ REQUEST(xWindowsWMQueryVersionReq);
+ swaps(&stuff->length, n);
+ return ProcWindowsWMQueryVersion(client);
+}
+
+static int
+SProcWindowsWMDispatch (register ClientPtr client)
+{
+ REQUEST(xReq);
+
+ /* It is bound to be non-local when there is byte swapping */
+ if (!LocalClient(client))
+ return WMErrorBase + WindowsWMClientNotLocal;
+
+ /* only local clients are allowed WM access */
+ switch (stuff->data)
+ {
+ case X_WindowsWMQueryVersion:
+ return SProcWindowsWMQueryVersion(client);
+ default:
+ return BadRequest;
+ }
+}
diff --git a/xorg-server/hw/xwin/xlaunch/config.h b/xorg-server/hw/xwin/xlaunch/config.h new file mode 100644 index 000000000..8448c54a4 --- /dev/null +++ b/xorg-server/hw/xwin/xlaunch/config.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2005 Alexander Gottwald + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Except as contained in this notice, the name(s) of the above copyright + * holders shall not be used in advertising or otherwise to promote the sale, + * use or other dealings in this Software without prior written authorization. + * + * Authors: Alexander Gottwald, Colin Harrison + */ +#ifndef __CONFIG_H__ +#define __CONFIG_H__ +#define UNICODE +#define _UNICODE + +#define PROG_NUMBER 10 +#define HOST_NUMBER 10 +#define MAX_MESSAGE 256 +#define MAX_CAPTION 128 + +#include <windows.h> +#include <string> +#include <vector> +struct CConfig +{ + enum {MultiWindow, Fullscreen, Windowed, Nodecoration} window; + enum {NoClient, StartProgram, XDMCP} client; + enum {NoXClient, Local, PuTTY, OpenSSH} clientstart; + bool local; + std::string display; + std::string protocol; + std::string protocol_path; + std::string program; + std::vector<std::string> progs; + bool compress; + std::string host; + std::string user; + std::string password; + bool password_save; + bool password_start; + bool broadcast; + bool indirect; + std::string xdmcp_host; + std::vector<std::string> xhosts; + bool clipboard; + bool no_access_control; + std::string font_server; + std::string extra_params; + std::string extra_ssh; + CConfig() : window(MultiWindow), client(NoClient), clientstart(NoXClient), display("0"), + protocol_path(""), program("xeyes"), progs(PROG_NUMBER), compress(false), host(""), user(""), + password(""), password_save(false), password_start(false), broadcast(false), + indirect(false), xdmcp_host(""), xhosts(HOST_NUMBER), clipboard(true), no_access_control(false), + font_server(), extra_params(), extra_ssh() {}; + void Load(const char * filename); + void Save(const char * filename); +}; + +#endif diff --git a/xorg-server/hw/xwin/xlaunch/makefile b/xorg-server/hw/xwin/xlaunch/makefile new file mode 100644 index 000000000..63b37dd1b --- /dev/null +++ b/xorg-server/hw/xwin/xlaunch/makefile @@ -0,0 +1,32 @@ +INCLUDELIBFILES = window\$(OBJDIR)\window.lib \
+ $(MHMAKECONF)\libx11\src\$(OBJDIR)\libx11.lib \
+ $(MHMAKECONF)\libxcb\src\$(OBJDIR)\libxcb.lib \
+ $(MHMAKECONF)\libxau\$(OBJDIR)\libxau.lib \
+ $(MHMAKECONF)\libx11\src\xlibi18n\$(OBJDIR)\libi18n.lib \
+ $(MHMAKECONF)\libx11\modules\lc\xlocale\$(OBJDIR)\libxlocale.lib \
+ $(MHMAKECONF)\libx11\modules\lc\utf8\$(OBJDIR)\libxlcUTF8Load.lib \
+ $(MHMAKECONF)\libx11\modules\lc\gen\$(OBJDIR)\liblcGenConvLoad.lib \
+ $(MHMAKECONF)\libx11\modules\lc\def\$(OBJDIR)\libxlcDef.lib \
+ $(MHMAKECONF)\libx11\src\xkb\$(OBJDIR)\libxkb.lib \
+ $(MHMAKECONF)\libx11\modules\im\ximcp\$(OBJDIR)\libximcp.lib \
+ $(MHMAKECONF)\libx11\modules\om\generic\$(OBJDIR)\libxomGeneric.lib
+
+CSRCS=config.cc main.cc
+
+WINAPP = xlaunch
+
+RESOURCES = resources.rc
+
+$(OBJDIR)\%.res : resources\%.rc
+ $(RC) $(RCFLAGS) $(RCDEFINES:%=-d "%") $(RCINCLUDES:%=-i %) -Fo$(relpath $@) $<
+
+LIBDIRS=$(dir $(INCLUDELIBFILES))
+
+load_makefile $(LIBDIRS:%$(OBJDIR)\=%makefile MAKESERVER=$(MAKESERVER) DEBUG=$(DEBUG);)
+
+ifeq ($(DEBUG),1)
+LINKLIBS += $(MHMAKECONF)\pthreads\pthreadVC2d.lib
+else
+LINKLIBS += $(MHMAKECONF)\pthreads\pthreadVC2.lib
+endif
+
|