4 Copyright 1993, 1998 The Open Group
5 Copyright (C) Colin Harrison 2005-2008
7 Permission to use, copy, modify, distribute, and sell this software and its
8 documentation for any purpose is hereby granted without fee, provided that
9 the above copyright notice appear in all copies and that both that
10 copyright notice and this permission notice appear in supporting
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name of The Open Group shall
25 not be used in advertising or otherwise to promote the sale, use or
26 other dealings in this Software without prior written authorization
31 #ifdef HAVE_XWIN_CONFIG_H
32 #include <xwin-config.h>
36 #include "winconfig.h"
39 #include "X11/Xlocale.h"
50 #ifdef RELOCATE_PROJECTROOT
51 #pragma push_macro("Status")
53 #define Status wStatus
55 #pragma pop_macro("Status")
56 typedef WINAPI
HRESULT(*SHGETFOLDERPATHPROC
) (HWND hwndOwner
,
59 DWORD dwFlags
, LPTSTR pszPath
);
62 #include "glx_extinit.h"
64 * References to external symbols
67 extern Bool g_fUnicodeClipboard
;
68 extern Bool g_fClipboardLaunched
;
69 extern Bool g_fClipboardStarted
;
70 extern pthread_t g_ptClipboardProc
;
71 extern HWND g_hwndClipboard
;
72 extern Bool g_fClipboard
;
81 winClipboardShutdown(void);
85 winCheckDisplayNumber(void);
88 winLogCommandLine(int argc
, char *argv
[]);
91 winLogVersionInfo(void);
94 winValidateArgs(void);
96 #ifdef RELOCATE_PROJECTROOT
97 const char *winGetBaseDir(void);
101 * For the depth 24 pixmap we default to 32 bits per pixel, but
102 * we change this pixmap format later if we detect that the display
103 * is going to be running at 24 bits per pixel.
105 * FIXME: On second thought, don't DIBs only support 32 bits per pixel?
106 * DIBs are the underlying bitmap used for DirectDraw surfaces, so it
107 * seems that all pixmap formats with depth 24 would be 32 bits per pixel.
108 * Confirm whether depth 24 DIBs can have 24 bits per pixel, then remove/keep
109 * the bits per pixel adjustment and update this comment to reflect the
110 * situation. Harold Hunt - 2002/07/02
113 static PixmapFormatRec g_PixmapFormats
[] = {
114 {1, 1, BITMAP_SCANLINE_PAD
},
115 {4, 8, BITMAP_SCANLINE_PAD
},
116 {8, 8, BITMAP_SCANLINE_PAD
},
117 {15, 16, BITMAP_SCANLINE_PAD
},
118 {16, 16, BITMAP_SCANLINE_PAD
},
119 {24, 32, BITMAP_SCANLINE_PAD
},
120 {32, 32, BITMAP_SCANLINE_PAD
}
123 const int NUMFORMATS
= sizeof(g_PixmapFormats
) / sizeof(g_PixmapFormats
[0]);
125 #ifdef XWIN_CLIPBOARD
127 winClipboardShutdown(void)
129 /* Close down clipboard resources */
130 if (g_fClipboard
&& g_fClipboardLaunched
&& g_fClipboardStarted
) {
131 /* Synchronously destroy the clipboard window */
132 if (g_hwndClipboard
!= NULL
) {
133 SendMessage(g_hwndClipboard
, WM_DESTROY
, 0, 0);
134 /* NOTE: g_hwndClipboard is set to NULL in winclipboardthread.c */
139 /* Wait for the clipboard thread to exit */
140 pthread_join(g_ptClipboardProc
, NULL
);
142 g_fClipboardLaunched
= FALSE
;
143 g_fClipboardStarted
= FALSE
;
145 winDebug("winClipboardShutdown - Clipboard thread has exited.\n");
150 static const ExtensionModule xwinExtensions
[] = {
152 { GlxExtensionInit
, "GLX", &noGlxExtension
},
158 * Initialises Xwin-specific extensions.
161 void XwinExtensionInit(void)
165 #ifdef XWIN_GLX_WINDOWS
167 /* install the native GL provider */
168 glxWinPushNativeProvider();
172 for (i
= 0; i
< ARRAY_SIZE(xwinExtensions
); i
++)
173 LoadExtension(&xwinExtensions
[i
], TRUE
);
176 #if defined(DDXBEFORERESET)
178 * Called right before KillAllClients when the server is going to reset,
179 * allows us to shutdown our seperate threads cleanly.
185 winDebug("ddxBeforeReset - Hello\n");
187 #ifdef XWIN_CLIPBOARD
188 winClipboardShutdown();
194 main(int argc
, char *argv
[], char *envp
[])
198 /* Create & acquire the termination mutex */
199 iReturn
= pthread_mutex_init(&g_pmTerminating
, NULL
);
201 ErrorF("ddxMain - pthread_mutex_init () failed: %d\n", iReturn
);
204 iReturn
= pthread_mutex_lock(&g_pmTerminating
);
206 ErrorF("ddxMain - pthread_mutex_lock () failed: %d\n", iReturn
);
209 return dix_main(argc
, argv
, envp
);
212 /* See Porting Layer Definition - p. 57 */
214 ddxGiveUp(enum ExitCode error
)
219 winDebug("ddxGiveUp\n");
222 /* Perform per-screen deinitialization */
223 for (i
= 0; i
< g_iNumScreens
; ++i
) {
224 /* Delete the tray icon */
225 if (!g_ScreenInfo
[i
].fNoTrayIcon
&& g_ScreenInfo
[i
].pScreen
)
226 winDeleteNotifyIcon(winGetScreenPriv(g_ScreenInfo
[i
].pScreen
));
229 #ifdef XWIN_MULTIWINDOW
230 /* Unload libraries for taskbar grouping */
231 winPropertyStoreDestroy();
233 /* Notify the worker threads we're exiting */
234 winDeinitMultiWindowWM();
237 #ifdef HAS_DEVWINDOWS
238 /* Close our handle to our message queue */
239 if (g_fdMessageQueue
!= WIN_FD_INVALID
) {
240 /* Close /dev/windows */
241 close(g_fdMessageQueue
);
243 /* Set the file handle to invalid */
244 g_fdMessageQueue
= WIN_FD_INVALID
;
249 g_pszLogFile
= LogInit(g_pszLogFile
, NULL
);
255 * At this point we aren't creating any new screens, so
256 * we are guaranteed to not need the DirectDraw functions.
258 winReleaseDDProcAddresses();
260 /* Free concatenated command line */
261 free(g_pszCommandLine
);
262 g_pszCommandLine
= NULL
;
264 /* Remove our keyboard hook if it is installed */
265 winRemoveKeyboardHookLL();
267 /* Tell Windows that we want to end the app */
271 winDebug("ddxGiveUp - Releasing termination mutex\n");
273 int iReturn
= pthread_mutex_unlock(&g_pmTerminating
);
276 ErrorF("winMsgWindowProc - pthread_mutex_unlock () failed: %d\n",
281 winDebug("ddxGiveUp - End\n");
284 /* See Porting Layer Definition - p. 57 */
286 AbortDDX(enum ExitCode error
)
289 winDebug("AbortDDX\n");
295 /* hasmntopt is currently not implemented for cygwin */
297 winCheckMntOpt(const struct mntent
*mnt
, const char *opt
)
306 if (mnt
->mnt_opts
== NULL
)
310 s
= strstr(mnt
->mnt_opts
, opt
);
313 if ((s
== mnt
->mnt_opts
|| *(s
- 1) == ',') &&
314 (s
[len
] == 0 || s
[len
] == ','))
325 enum { none
= 0, sys_root
, user_root
, sys_tmp
, user_tmp
}
326 level
= none
, curlevel
;
329 mnt
= setmntent("/etc/mtab", "r");
331 ErrorF("setmntent failed");
335 while ((ent
= getmntent(mnt
)) != NULL
) {
336 BOOL sys
= (winCheckMntOpt(ent
, "user") != NULL
);
337 BOOL root
= (strcmp(ent
->mnt_dir
, "/") == 0);
338 BOOL tmp
= (strcmp(ent
->mnt_dir
, "/tmp") == 0);
350 curlevel
= user_root
;
357 if (curlevel
<= level
)
361 if ((winCheckMntOpt(ent
, "binary") == NULL
) &&
362 (winCheckMntOpt(ent
, "binmode") == NULL
))
368 if (endmntent(mnt
) != 1) {
369 ErrorF("endmntent failed");
374 winMsg(X_WARNING
, "/tmp mounted in textmode\n");
383 #ifdef RELOCATE_PROJECTROOT
387 static BOOL inited
= FALSE
;
388 static char buffer
[MAX_PATH
];
392 HMODULE module
= GetModuleHandle(NULL
);
393 DWORD size
= GetModuleFileName(module
, buffer
, sizeof(buffer
));
395 if (sizeof(buffer
) > 0)
396 buffer
[sizeof(buffer
) - 1] = 0;
398 fendptr
= buffer
+ size
;
399 while (fendptr
> buffer
) {
400 if (*fendptr
== '\\' || *fendptr
== '/') {
415 BOOL changed_fontpath
= FALSE
;
416 MessageType font_from
= X_DEFAULT
;
418 #ifdef RELOCATE_PROJECTROOT
419 const char *basedir
= winGetBaseDir();
420 size_t basedirlen
= strlen(basedir
);
425 /* Open fontpath configuration file */
426 FILE *fontdirs
= fopen(ETCX11DIR
"/font-dirs", "rt");
428 if (fontdirs
!= NULL
) {
430 int needs_sep
= TRUE
;
431 int comment_block
= FALSE
;
433 /* get default fontpath */
434 char *fontpath
= strdup(defaultFontPath
);
435 size_t size
= strlen(fontpath
);
438 while (!feof(fontdirs
)) {
445 str
= fgets(buffer
, sizeof(buffer
), fontdirs
);
446 if (str
== NULL
) /* stop on error or eof */
449 if (strchr(str
, '\n') != NULL
)
452 /* check if block is continued comment */
454 /* ignore all input */
457 if (has_eol
) /* check if line ended in this block */
458 comment_block
= FALSE
;
461 /* find comment character. ignore all trailing input */
462 hashchar
= strchr(str
, '#');
463 if (hashchar
!= NULL
) {
465 if (!has_eol
) /* mark next block as continued comment */
466 comment_block
= TRUE
;
470 /* strip whitespaces from beginning */
471 while (*str
== ' ' || *str
== '\t')
474 /* get size, strip whitespaces from end */
476 while (blen
> 0 && (str
[blen
- 1] == ' ' ||
477 str
[blen
- 1] == '\t' ||
478 str
[blen
- 1] == '\n')) {
482 /* still something left to add? */
484 size_t newsize
= size
+ blen
;
486 /* reserve one character more for ',' */
490 /* allocate memory */
491 if (fontpath
== NULL
)
492 fontpath
= malloc(newsize
+ 1);
494 fontpath
= realloc(fontpath
, newsize
+ 1);
498 fontpath
[size
] = ',';
503 /* mark next line as new entry */
508 strncpy(fontpath
+ size
, str
, blen
);
509 fontpath
[newsize
] = 0;
516 defaultFontPath
= strdup(fontpath
);
518 changed_fontpath
= TRUE
;
519 font_from
= X_CONFIG
;
522 #endif /* READ_FONTDIRS */
523 #ifdef RELOCATE_PROJECTROOT
525 const char *libx11dir
= PROJECTROOT
"/lib/X11";
526 size_t libx11dir_len
= strlen(libx11dir
);
528 size_t newfp_len
= 0;
529 const char *endptr
, *ptr
, *oldptr
= defaultFontPath
;
531 endptr
= oldptr
+ strlen(oldptr
);
532 ptr
= strchr(oldptr
, ',');
535 while (ptr
!= NULL
) {
536 size_t oldfp_len
= (ptr
- oldptr
);
537 size_t newsize
= oldfp_len
;
538 char *newpath
= malloc(newsize
+ 1);
540 strncpy(newpath
, oldptr
, newsize
);
541 newpath
[newsize
] = 0;
543 if (strncmp(libx11dir
, newpath
, libx11dir_len
) == 0) {
546 newsize
= newsize
- libx11dir_len
+ basedirlen
;
547 compose
= malloc(newsize
+ 1);
548 strcpy(compose
, basedir
);
549 strncat(compose
, newpath
+ libx11dir_len
, newsize
- basedirlen
);
550 compose
[newsize
] = 0;
555 oldfp_len
= newfp_len
;
557 newfp_len
++; /* space for separator */
558 newfp_len
+= newsize
;
561 newfp
= malloc(newfp_len
+ 1);
563 newfp
= realloc(newfp
, newfp_len
+ 1);
566 strcpy(newfp
+ oldfp_len
, ",");
569 strcpy(newfp
+ oldfp_len
, newpath
);
579 ptr
= strchr(oldptr
, ',');
585 defaultFontPath
= strdup(newfp
);
587 changed_fontpath
= TRUE
;
589 #endif /* RELOCATE_PROJECTROOT */
590 if (changed_fontpath
)
591 winMsg(font_from
, "FontPath set to \"%s\"\n", defaultFontPath
);
593 #ifdef RELOCATE_PROJECTROOT
594 if (getenv("XKEYSYMDB") == NULL
) {
595 char buffer
[MAX_PATH
];
597 snprintf(buffer
, sizeof(buffer
), "XKEYSYMDB=%s\\XKeysymDB", basedir
);
598 buffer
[sizeof(buffer
) - 1] = 0;
601 if (getenv("XERRORDB") == NULL
) {
602 char buffer
[MAX_PATH
];
604 snprintf(buffer
, sizeof(buffer
), "XERRORDB=%s\\XErrorDB", basedir
);
605 buffer
[sizeof(buffer
) - 1] = 0;
608 if (getenv("XLOCALEDIR") == NULL
) {
609 char buffer
[MAX_PATH
];
611 snprintf(buffer
, sizeof(buffer
), "XLOCALEDIR=%s\\locale", basedir
);
612 buffer
[sizeof(buffer
) - 1] = 0;
615 if (getenv("HOME") == NULL
) {
616 char buffer
[MAX_PATH
+ 5];
618 strncpy(buffer
, "HOME=", 5);
620 /* query appdata directory */
622 (NULL
, CSIDL_APPDATA
| CSIDL_FLAG_CREATE
, NULL
, 0,
627 winMsg(X_ERROR
, "Can not determine HOME directory\n");
630 if (!g_fLogFileChanged
) {
631 static char buffer
[MAX_PATH
];
632 DWORD size
= GetTempPath(sizeof(buffer
), buffer
);
634 if (size
&& size
< sizeof(buffer
)) {
635 snprintf(buffer
+ size
, sizeof(buffer
) - size
,
636 "XWin.%s.log", display
);
637 buffer
[sizeof(buffer
) - 1] = 0;
638 g_pszLogFile
= buffer
;
639 winMsg(X_DEFAULT
, "Logfile set to \"%s\"\n", g_pszLogFile
);
643 static char xkbbasedir
[MAX_PATH
];
645 snprintf(xkbbasedir
, sizeof(xkbbasedir
), "%s\\xkb", basedir
);
646 if (sizeof(xkbbasedir
) > 0)
647 xkbbasedir
[sizeof(xkbbasedir
) - 1] = 0;
648 XkbBaseDirectory
= xkbbasedir
;
649 XkbBinDirectory
= basedir
;
651 #endif /* RELOCATE_PROJECTROOT */
657 /* Re-initialize global variables on server reset */
658 winInitializeGlobals();
663 if (!OsVendorVErrorFProc
)
664 OsVendorVErrorFProc
= OsVendorVErrorF
;
668 /* keep this order. If LogInit fails it calls Abort which then calls
669 * ddxGiveUp where LogInit is called again and creates an infinite
670 * recursion. If we set g_fLogInited to TRUE before the init we
671 * avoid the second call
674 g_pszLogFile
= LogInit(g_pszLogFile
, NULL
);
676 LogSetParameter(XLOG_FLUSH
, 1);
677 LogSetParameter(XLOG_VERBOSITY
, g_iLogVerbose
);
678 LogSetParameter(XLOG_FILE_VERBOSITY
, g_iLogVerbose
);
680 /* Log the version information */
681 if (serverGeneration
== 1)
686 /* Add a default screen if no screens were specified */
687 if (g_iNumScreens
== 0) {
688 winDebug("OsVendorInit - Creating default screen 0\n");
691 * We need to initialize the default screen 0 if no -screen
692 * arguments were processed.
694 * Add a screen 0 using the defaults set by winInitializeDefaultScreens()
695 * and any additional default screen parameters given
697 winInitializeScreens(1);
699 /* We have to flag this as an explicit screen, even though it isn't */
700 g_ScreenInfo
[0].fExplicitScreen
= TRUE
;
703 /* Work out what the default emulate3buttons setting should be, and apply
704 it if nothing was explicitly specified */
706 int mouseButtons
= GetSystemMetrics(SM_CMOUSEBUTTONS
);
709 for (j
= 0; j
< g_iNumScreens
; j
++) {
710 if (g_ScreenInfo
[j
].iE3BTimeout
== WIN_E3B_DEFAULT
) {
711 if (mouseButtons
< 3) {
712 static Bool reportOnce
= TRUE
;
714 g_ScreenInfo
[j
].iE3BTimeout
= WIN_DEFAULT_E3B_TIME
;
718 "Windows reports only %d mouse buttons, defaulting to -emulate3buttons\n",
723 g_ScreenInfo
[j
].iE3BTimeout
= WIN_E3B_OFF
;
735 ErrorF(EXECUTABLE_NAME
" Device Dependent Usage:\n");
738 #ifdef XWIN_CLIPBOARD
739 ErrorF("-[no]clipboard\n"
740 "\tEnable [disable] the clipboard integration. Default is enabled.\n");
743 ErrorF("-clipupdates num_boxes\n"
744 "\tUse a clipping region to constrain shadow update blits to\n"
745 "\tthe updated region when num_boxes, or more, are in the\n"
746 "\tupdated region.\n");
748 #ifdef XWIN_XF86CONFIG
749 ErrorF("-config\n" "\tSpecify a configuration file.\n");
751 ErrorF("-configdir\n" "\tSpecify a configuration directory.\n");
754 ErrorF("-depth bits_per_pixel\n"
755 "\tSpecify an optional bitdepth to use in fullscreen mode\n"
756 "\twith a DirectDraw engine.\n");
758 ErrorF("-[no]emulate3buttons [timeout]\n"
759 "\tEmulate 3 button mouse with an optional timeout in\n"
760 "\tmilliseconds.\n");
762 #ifdef XWIN_EMULATEPSEUDO
763 ErrorF("-emulatepseudo\n"
764 "\tCreate a depth 8 PseudoColor visual when running in\n"
765 "\tdepths 15, 16, 24, or 32, collectively known as TrueColor\n"
766 "\tdepths. The PseudoColor visual does not have correct colors,\n"
767 "\tand it may crash, but it at least allows you to run your\n"
768 "\tapplication in TrueColor modes.\n");
771 ErrorF("-engine engine_type_id\n"
772 "\tOverride the server's automatically selected engine type:\n"
773 "\t\t1 - Shadow GDI\n"
774 "\t\t2 - Shadow DirectDraw\n"
775 "\t\t4 - Shadow DirectDraw4 Non-Locking\n"
776 #ifdef XWIN_PRIMARYFB
777 "\t\t8 - Primary DirectDraw - obsolete\n"
779 #ifdef XWIN_NATIVEGDI
780 "\t\t16 - Native GDI - experimental\n"
784 ErrorF("-fullscreen\n" "\tRun the server in fullscreen mode.\n");
786 ErrorF("-ignoreinput\n" "\tIgnore keyboard and mouse input.\n");
788 #ifdef XWIN_MULTIWINDOWEXTWM
789 ErrorF("-internalwm\n" "\tRun the internal window manager.\n");
792 #ifdef XWIN_XF86CONFIG
794 "\tSpecify a keyboard device from the configuration file.\n");
797 ErrorF("-[no]keyhook\n"
798 "\tGrab special Windows keypresses like Alt-Tab or the Menu "
801 ErrorF("-lesspointer\n"
802 "\tHide the windows mouse pointer when it is over any\n"
804 " window. This prevents ghost cursors appearing when\n"
805 "\tthe Windows cursor is drawn on top of the X cursor\n");
807 ErrorF("-logfile filename\n" "\tWrite log messages to <filename>.\n");
809 ErrorF("-logverbose verbosity\n"
810 "\tSet the verbosity of log messages. [NOTE: Only a few messages\n"
811 "\trespect the settings yet]\n"
812 "\t\t0 - only print fatal error.\n"
813 "\t\t1 - print additional configuration information.\n"
814 "\t\t2 - print additional runtime information [default].\n"
815 "\t\t3 - print debugging and tracing information.\n");
817 ErrorF("-[no]multimonitors or -[no]multiplemonitors\n"
818 "\tUse the entire virtual screen if multiple\n"
819 "\tmonitors are present.\n");
821 #ifdef XWIN_MULTIWINDOW
822 ErrorF("-multiwindow\n" "\tRun the server in multi-window mode.\n");
825 #ifdef XWIN_MULTIWINDOWEXTWM
827 "\tRun the server in multi-window external window manager mode.\n");
830 ErrorF("-nodecoration\n"
831 "\tDo not draw a window border, title bar, etc. Windowed\n"
834 #ifdef XWIN_CLIPBOARD
835 ErrorF("-nounicodeclipboard\n"
836 "\tDo not use Unicode clipboard even if on a NT-based platform.\n");
839 ErrorF("-refresh rate_in_Hz\n"
840 "\tSpecify an optional refresh rate to use in fullscreen mode\n"
841 "\twith a DirectDraw engine.\n");
843 ErrorF("-resize=none|scrollbars|randr"
844 "\tIn windowed mode, [don't] allow resizing of the window. 'scrollbars'\n"
845 "\tmode gives the window scrollbars as needed, 'randr' mode uses the RANR\n"
846 "\textension to resize the X screen. 'randr' is the default.\n");
848 ErrorF("-rootless\n" "\tRun the server in rootless mode.\n");
850 ErrorF("-screen scr_num [width height [x y] | [[WxH[+X+Y]][@m]] ]\n"
851 "\tEnable screen scr_num and optionally specify a width and\n"
852 "\theight and initial position for that screen. Additionally\n"
853 "\ta monitor number can be specified to start the server on,\n"
854 "\tat which point, all coordinates become relative to that\n"
855 "\tmonitor. Examples:\n"
856 "\t -screen 0 800x600+100+100@2 ; 2nd monitor offset 100,100 size 800x600\n"
857 "\t -screen 0 1024x768@3 ; 3rd monitor size 1024x768\n"
858 "\t -screen 0 @1 ; on 1st monitor using its full resolution (the default)\n");
860 ErrorF("-silent-dup-error\n"
861 "\tIf another instance of " EXECUTABLE_NAME
862 " with the same display number is running\n"
863 "\texit silently and don't display any error message.\n");
866 "\tDisable the usage of the Windows cursor and use the X11 software\n"
867 "\tcursor instead.\n");
869 ErrorF("-[no]trayicon\n"
870 "\tDo not create a tray icon. Default is to create one\n"
871 "\ticon per screen. You can globally disable tray icons with\n"
872 "\t-notrayicon, then enable it for specific screens with\n"
873 "\t-trayicon for those screens.\n");
875 ErrorF("-[no]unixkill\n" "\tCtrl+Alt+Backspace exits the X Server.\n");
877 #ifdef XWIN_GLX_WINDOWS
879 "\tEnable the GLX extension to use the native Windows WGL interface for hardware-accelerated OpenGL\n");
882 ErrorF("-[no]winkill\n" "\tAlt+F4 exits the X Server.\n");
884 ErrorF("-xkblayout XKBLayout\n"
885 "\tEquivalent to XKBLayout in XF86Config files.\n"
886 "\tFor example: -xkblayout de\n");
888 ErrorF("-xkbmodel XKBModel\n"
889 "\tEquivalent to XKBModel in XF86Config files.\n");
891 ErrorF("-xkboptions XKBOptions\n"
892 "\tEquivalent to XKBOptions in XF86Config files.\n");
894 ErrorF("-xkbrules XKBRules\n"
895 "\tEquivalent to XKBRules in XF86Config files.\n");
897 ErrorF("-xkbvariant XKBVariant\n"
898 "\tEquivalent to XKBVariant in XF86Config files.\n"
899 "\tFor example: -xkbvariant nodeadkeys\n");
902 /* See Porting Layer Definition - p. 57 */
906 /* Set a flag so that FatalError won't give duplicate warning message */
907 g_fSilentFatalError
= TRUE
;
911 /* Log file will not be opened for UseMsg unless we open it now */
913 g_pszLogFile
= LogInit(g_pszLogFile
, NULL
);
916 LogClose(EXIT_NO_ERROR
);
918 /* Notify user where UseMsg text can be found. */
919 if (!g_fNoHelpMessageBox
)
920 winMessageBoxF("The " PROJECT_NAME
" help text has been printed to "
922 "Please open %s to read the help text.\n",
923 MB_ICONINFORMATION
, g_pszLogFile
, g_pszLogFile
);
926 /* See Porting Layer Definition - p. 20 */
928 * Do any global initialization, then initialize each screen.
930 * NOTE: We use ddxProcessArgument, so we don't need to touch argc and argv
934 InitOutput(ScreenInfo
* pScreenInfo
, int argc
, char *argv
[])
938 if (serverGeneration
== 1)
941 /* Log the command line */
942 winLogCommandLine(argc
, argv
);
945 winDebug("InitOutput\n");
948 /* Validate command-line arguments */
949 if (serverGeneration
== 1 && !winValidateArgs()) {
950 FatalError("InitOutput - Invalid command-line arguments found. "
954 /* Check for duplicate invocation on same display number. */
955 if (serverGeneration
== 1 && !winCheckDisplayNumber()) {
956 if (g_fSilentDupError
)
957 g_fSilentFatalError
= TRUE
;
958 FatalError("InitOutput - Duplicate invocation on display "
959 "number: %s. Exiting.\n", display
);
962 #ifdef XWIN_XF86CONFIG
963 /* Try to read the xorg.conf-style configuration file */
964 if (!winReadConfigfile())
965 winErrorFVerb(1, "InitOutput - Error reading config file\n");
967 winMsg(X_INFO
, "xorg.conf is not supported\n");
968 winMsg(X_INFO
, "See http://x.cygwin.com/docs/faq/cygwin-x-faq.html "
969 "for more information\n");
973 /* Load preferences from XWinrc file */
976 /* Setup global screen info parameters */
977 pScreenInfo
->imageByteOrder
= IMAGE_BYTE_ORDER
;
978 pScreenInfo
->bitmapScanlinePad
= BITMAP_SCANLINE_PAD
;
979 pScreenInfo
->bitmapScanlineUnit
= BITMAP_SCANLINE_UNIT
;
980 pScreenInfo
->bitmapBitOrder
= BITMAP_BIT_ORDER
;
981 pScreenInfo
->numPixmapFormats
= NUMFORMATS
;
983 /* Describe how we want common pixmap formats padded */
984 for (i
= 0; i
< NUMFORMATS
; i
++) {
985 pScreenInfo
->formats
[i
] = g_PixmapFormats
[i
];
988 /* Load pointers to DirectDraw functions */
989 winGetDDProcAddresses();
991 /* Detect supported engines */
992 winDetectSupportedEngines();
993 #ifdef XWIN_MULTIWINDOW
994 /* Load libraries for taskbar grouping */
995 winPropertyStoreInit();
998 /* Store the instance handle */
999 g_hInstance
= GetModuleHandle(NULL
);
1001 /* Create the messaging window */
1002 if (serverGeneration
== 1)
1003 winCreateMsgWindowThread();
1005 /* Initialize each screen */
1006 for (i
= 0; i
< g_iNumScreens
; ++i
) {
1007 /* Initialize the screen */
1008 if (-1 == AddScreen(winScreenInit
, argc
, argv
)) {
1009 FatalError("InitOutput - Couldn't add screen %d", i
);
1013 #if defined(XWIN_CLIPBOARD) || defined(XWIN_MULTIWINDOW)
1015 /* Generate a cookie used by internal clients for authorization */
1016 if (g_fXdmcpEnabled
|| g_fAuthEnabled
)
1017 winGenerateAuthorization();
1019 /* Perform some one time initialization */
1020 if (1 == serverGeneration
) {
1022 * setlocale applies to all threads in the current process.
1023 * Apply locale specified in LANG environment variable.
1025 setlocale(LC_ALL
, "");
1030 winDebug("InitOutput - Returning.\n");
1035 * winCheckDisplayNumber - Check if another instance of Cygwin/X is
1036 * already running on the same display number. If no one exists,
1037 * make a mutex to prevent new instances from running on the same display.
1039 * return FALSE if the display number is already used.
1043 winCheckDisplayNumber(void)
1047 char name
[MAX_PATH
];
1048 char *pszPrefix
= '\0';
1049 OSVERSIONINFO osvi
= { 0 };
1051 /* Check display range */
1052 nDisp
= atoi(display
);
1053 if (nDisp
< 0 || nDisp
> 65535) {
1054 ErrorF("winCheckDisplayNumber - Bad display number: %d\n", nDisp
);
1058 /* Set first character of mutex name to null */
1061 /* Get operating system version information */
1062 osvi
.dwOSVersionInfoSize
= sizeof(osvi
);
1063 GetVersionEx(&osvi
);
1065 /* Want a mutex shared among all terminals on NT > 4.0 */
1066 if (osvi
.dwPlatformId
== VER_PLATFORM_WIN32_NT
&& osvi
.dwMajorVersion
>= 5) {
1067 pszPrefix
= "Global\\";
1070 /* Setup Cygwin/X specific part of name */
1071 snprintf(name
, sizeof(name
), "%sCYGWINX_DISPLAY:%d", pszPrefix
, nDisp
);
1073 /* Windows automatically releases the mutex when this process exits */
1074 mutex
= CreateMutex(NULL
, FALSE
, name
);
1078 /* Display a fancy error message */
1079 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
|
1080 FORMAT_MESSAGE_FROM_SYSTEM
|
1081 FORMAT_MESSAGE_IGNORE_INSERTS
,
1084 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
1085 (LPTSTR
) &lpMsgBuf
, 0, NULL
);
1086 ErrorF("winCheckDisplayNumber - CreateMutex failed: %s\n",
1088 LocalFree(lpMsgBuf
);
1092 if (GetLastError() == ERROR_ALREADY_EXISTS
) {
1093 ErrorF("winCheckDisplayNumber - "
1094 PROJECT_NAME
" is already running on display %d\n", nDisp
);