#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(XKB) && defined(WIN32)
#include <X11/extensions/XKBsrv.h>
#endif
#ifdef RELOCATE_PROJECTROOT
#include <shlobj.h>
typedef HRESULT (*SHGETFOLDERPATHPROC)(
HWND hwndOwner,
int nFolder,
HANDLE hToken,
DWORD dwFlags,
LPTSTR pszPath
);
#endif
extern int g_iNumScreens;
extern winScreenInfo g_ScreenInfo[];
extern int g_iLastScreen;
extern char * g_pszCommandLine;
extern Bool g_fSilentFatalError;
extern char * g_pszLogFile;
extern Bool g_fLogFileChanged;
extern int g_iLogVerbose;
Bool g_fLogInited;
extern Bool g_fXdmcpEnabled;
#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;
#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 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)
{
if (g_fClipboard && g_fClipboardLaunched && g_fClipboardStarted)
{
if (g_hwndClipboard != NULL)
{
SendMessage (g_hwndClipboard, WM_DESTROY, 0, 0);
}
else
return;
pthread_join (g_ptClipboardProc, NULL);
g_fClipboardLaunched = FALSE;
g_fClipboardStarted = FALSE;
winDebug ("winClipboardShutdown - Clipboard thread has exited.\n");
}
}
#endif
#if defined(DDXBEFORERESET)
void
ddxBeforeReset (void)
{
winDebug ("ddxBeforeReset - Hello\n");
#ifdef XWIN_CLIPBOARD
winClipboardShutdown ();
#endif
}
#endif
void
ddxGiveUp (void)
{
int i;
#if CYGDEBUG
winDebug ("ddxGiveUp\n");
#endif
for (i = 0; i < g_iNumScreens; ++i)
{
if (!g_ScreenInfo[i].fNoTrayIcon && g_ScreenInfo[i].pScreen)
winDeleteNotifyIcon (winGetScreenPriv (g_ScreenInfo[i].pScreen));
}
#ifdef XWIN_MULTIWINDOW
winDeinitMultiWindowWM ();
#endif
#ifdef HAS_DEVWINDOWS
if (g_fdMessageQueue != WIN_FD_INVALID)
{
close (g_fdMessageQueue);
g_fdMessageQueue = WIN_FD_INVALID;
}
#endif
if (!g_fLogInited) {
LogInit (g_pszLogFile, NULL);
g_fLogInited = TRUE;
}
LogClose ();
if (g_hmodDirectDraw != NULL)
{
FreeLibrary (g_hmodDirectDraw);
g_hmodDirectDraw = NULL;
g_fpDirectDrawCreate = NULL;
g_fpDirectDrawCreateClipper = NULL;
}
if (g_hmodCommonControls != NULL)
{
FreeLibrary (g_hmodCommonControls);
g_hmodCommonControls = NULL;
g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA;
}
if (g_pszCommandLine)
{
free (g_pszCommandLine);
g_pszCommandLine = NULL;
}
winRemoveKeyboardHookLL ();
PostQuitMessage (0);
}
void
AbortDDX (void)
{
#if CYGDEBUG
winDebug ("AbortDDX\n");
#endif
ddxGiveUp ();
}
#ifdef __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;
}
if (!binary)
winMsg(X_WARNING, "/tmp mounted int textmode\n");
}
#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
{
FILE *fontdirs = fopen(ETCX11DIR "/font-dirs", "rt");
if (fontdirs != NULL)
{
char buffer[256];
int needs_sep = TRUE;
int comment_block = FALSE;
char *fontpath = xstrdup(defaultFontPath);
size_t size = strlen(fontpath);
while (!feof(fontdirs))
{
size_t blen;
char *hashchar;
char *str;
int has_eol = FALSE;
str = fgets(buffer, sizeof(buffer), fontdirs);
if (str == NULL)
break;
if (strchr(str, '\n') != NULL)
has_eol = TRUE;
if (comment_block)
{
*str = 0;
blen = 0;
if (has_eol)
comment_block = FALSE;
}
else
{
hashchar = strchr(str, '#');
if (hashchar != NULL)
{
*hashchar = 0;
if (!has_eol)
comment_block = TRUE;
}
}
while (*str == ' ' || *str == '\t')
str++;
blen = strlen(str);
while (blen > 0 && (str[blen-1] == ' ' ||
str[blen-1] == '\t' || str[blen-1] == '\n'))
{
str[--blen] = 0;
}
if (blen > 0)
{
size_t newsize = size + blen;
if (needs_sep)
newsize++;
if (fontpath == NULL)
fontpath = malloc(newsize+1);
else
fontpath = realloc(fontpath, newsize+1);
if (needs_sep)
{
fontpath[size] = ',';
size++;
needs_sep = FALSE;
}
if (has_eol)
needs_sep = TRUE;
strncpy(fontpath + size, str, blen);
fontpath[newsize] = 0;
size = newsize;
}
}
fclose(fontdirs);
defaultFontPath = xstrdup(fontpath);
free(fontpath);
changed_fontpath = TRUE;
font_from = X_CONFIG;
}
}
#endif
#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 ++;
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
if (changed_fontpath)
winMsg (font_from, "FontPath set to \"%s\"\n", defaultFontPath);
#ifdef RELOCATE_PROJECTROOT
if (1) {
const char *libx11dir = "/usr/X11R6/lib/X11";
size_t libx11dir_len = strlen(libx11dir);
if (strncmp(libx11dir, rgbPath, libx11dir_len) == 0)
{
size_t newsize = strlen(rgbPath) - libx11dir_len + basedirlen;
char *compose = malloc(newsize + 1);
strcpy(compose, basedir);
strcat(compose, rgbPath + libx11dir_len);
compose[newsize] = 0;
rgbPath = xstrdup (compose);
free (compose);
winMsg (X_DEFAULT, "RgbPath set to \"%s\"\n", rgbPath);
}
}
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("HOME") == NULL)
{
HMODULE shfolder;
SHGETFOLDERPATHPROC shgetfolderpath = NULL;
char buffer[MAX_PATH + 5];
strncpy(buffer, "HOME=", 5);
shfolder = LoadLibrary("shfolder.dll");
if (shfolder == NULL)
shfolder = LoadLibrary("shell32.dll");
if (shfolder != NULL)
shgetfolderpath = (SHGETFOLDERPATHPROC)GetProcAddress(shfolder, "SHGetFolderPathA");
if (shgetfolderpath &&
shgetfolderpath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0,
buffer + 5) == 0)
{
putenv(buffer);
} else
{
winMsg (X_ERROR, "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,
"XWin.%s.log", display);
buffer[sizeof(buffer)-1] = 0;
g_pszLogFile = buffer;
winMsg (X_DEFAULT, "Logfile set to \"%s\"\n", g_pszLogFile);
}
}
#ifdef XKB
{
static char xkbbasedir[MAX_PATH];
snprintf(xkbbasedir, sizeof(xkbbasedir), "%s\\xkb", basedir);
if (sizeof(xkbbasedir) > 0)
xkbbasedir[sizeof(xkbbasedir)-1] = 0;
XkbBaseDirectory = xkbbasedir;
XkbBinDirectory = basedir;
}
#endif
#endif
}
void
OsVendorInit (void)
{
winInitializeGlobals ();
LogInit (NULL, NULL);
LogSetParameter (XLOG_VERBOSITY, g_iLogVerbose);
winFixupPaths();
#ifdef DDXOSVERRORF
if (!OsVendorVErrorFProc)
OsVendorVErrorFProc = OsVendorVErrorF;
#endif
if (!g_fLogInited) {
g_fLogInited = TRUE;
LogInit (g_pszLogFile, NULL);
}
LogSetParameter (XLOG_FLUSH, 1);
LogSetParameter (XLOG_VERBOSITY, g_iLogVerbose);
LogSetParameter (XLOG_FILE_VERBOSITY, 1);
if (serverGeneration == 1)
winLogVersionInfo ();
winCheckMount();
if (g_iNumScreens == 0)
{
winDebug ("OsVendorInit - Creating bogus screen 0\n");
winInitializeDefaultScreens ();
g_iNumScreens = 1;
g_iLastScreen = 0;
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
#ifdef XKB
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");
#endif
ErrorF ("-logfile filename\n"
"\tWrite logmessages to <filename> instead of /tmp/Xwin.log.\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");
}
void
ddxUseMsg(void)
{
g_fSilentFatalError = TRUE;
winUseMsg();
if (!g_fLogInited) {
LogInit (g_pszLogFile, NULL);
g_fLogInited = TRUE;
}
LogClose ();
if (!g_fNoHelpMessageBox)
winMessageBoxF ("The " PROJECT_NAME " help text has been printed to "
"/tmp/XWin.log.\n"
"Please open /tmp/XWin.log to read the help text.\n",
MB_ICONINFORMATION);
}
void ddxInitGlobals(void)
{
}
void
InitOutput (ScreenInfo *screenInfo, int argc, char *argv[])
{
int i;
winLogCommandLine (argc, argv);
#if CYGDEBUG
winDebug ("InitOutput\n");
#endif
if (serverGeneration == 1 && !winValidateArgs ())
{
FatalError ("InitOutput - Invalid command-line arguments found. "
"Exiting.\n");
}
if (serverGeneration == 1 && !winCheckDisplayNumber ())
{
if (g_fSilentDupError)
g_fSilentFatalError = TRUE;
FatalError ("InitOutput - Duplicate invocation on display "
"number: %s. Exiting.\n", display);
}
#ifdef XWIN_XF86CONFIG
if (!winReadConfigfile ())
winErrorFVerb (1, "InitOutput - Error reading config file\n");
#else
winMsg(X_INFO, "XF86Config is not supported\n");
winMsg(X_INFO, "See http://x.cygwin.com/docs/faq/cygwin-x-faq.html "
"for more information\n");
winConfigFiles ();
#endif
LoadPreferences();
screenInfo->imageByteOrder = IMAGE_BYTE_ORDER;
screenInfo->bitmapScanlinePad = BITMAP_SCANLINE_PAD;
screenInfo->bitmapScanlineUnit = BITMAP_SCANLINE_UNIT;
screenInfo->bitmapBitOrder = BITMAP_BIT_ORDER;
screenInfo->numPixmapFormats = NUMFORMATS;
for (i = 0; i < NUMFORMATS; i++)
{
screenInfo->formats[i] = g_PixmapFormats[i];
}
winGetDDProcAddresses ();
winDetectSupportedEngines ();
g_hmodCommonControls = LoadLibraryEx ("comctl32.dll", NULL, 0);
g_fpTrackMouseEvent = GetProcAddress (g_hmodCommonControls,
"_TrackMouseEvent");
if (g_fpTrackMouseEvent == NULL)
{
winErrorFVerb (1, "InitOutput - Could not get pointer to function\n"
"\t_TrackMouseEvent in comctl32.dll. Try installing\n"
"\tInternet Explorer 3.0 or greater if you have not\n"
"\talready.\n");
FreeLibrary (g_hmodCommonControls);
g_hmodCommonControls = NULL;
g_fpTrackMouseEvent = (FARPROC) (void (*)(void))NoopDDA;
}
g_hInstance = GetModuleHandle (NULL);
for (i = 0; i < g_iNumScreens; ++i)
{
if (-1 == AddScreen (winScreenInit, argc, argv))
{
FatalError ("InitOutput - Couldn't add screen %d", i);
}
}
#if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
#if defined(XCSECURITY)
if (g_fXdmcpEnabled)
winGenerateAuthorization ();
#endif
if (1 == serverGeneration)
{
setlocale (LC_ALL, "");
}
#endif
#if CYGDEBUG || YES
winDebug ("InitOutput - Returning.\n");
#endif
}
static Bool
winCheckDisplayNumber ()
{
int nDisp;
HANDLE mutex;
char name[MAX_PATH];
char * pszPrefix = '\0';
OSVERSIONINFO osvi = {0};
nDisp = atoi (display);
if (nDisp < 0 || nDisp > 65535)
{
ErrorF ("winCheckDisplayNumber - Bad display number: %d\n", nDisp);
return FALSE;
}
name[0] = '\0';
osvi.dwOSVersionInfoSize = sizeof (osvi);
GetVersionEx (&osvi);
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT
&& osvi.dwMajorVersion >= 5)
{
pszPrefix = "Global\\";
}
snprintf (name, sizeof(name), "%sCYGWINX_DISPLAY:%d", pszPrefix, nDisp);
mutex = CreateMutex (NULL, FALSE, name);
if (!mutex)
{
LPVOID lpMsgBuf;
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 - "
PROJECT_NAME " is already running on display %d\n",
nDisp);
return FALSE;
}
return TRUE;
}
#ifdef DPMSExtension
Bool DPMSSupported(void)
{
return FALSE;
}
void DPMSSet(int level)
{
return;
}
int DPMSGet(int *plevel)
{
return 0;
}
#endif