Sweden-Number/windows/x11drv/main.c

354 lines
12 KiB
C
Raw Normal View History

1999-02-04 12:11:01 +01:00
/*
* X11 main driver
*
* Copyright 1998 Patrik Stridvall
*
*/
#include "config.h"
#ifndef X_DISPLAY_MISSING
#include <X11/Xlocale.h>
#include "ts_xlib.h"
#include "ts_xresource.h"
#include "ts_xutil.h"
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "clipboard.h"
1999-02-04 12:11:01 +01:00
#include "console.h"
#include "debugtools.h"
1999-02-04 12:11:01 +01:00
#include "desktop.h"
#include "keyboard.h"
1999-02-04 12:11:01 +01:00
#include "main.h"
#include "message.h"
1999-02-04 12:11:01 +01:00
#include "monitor.h"
#include "mouse.h"
1999-02-04 12:11:01 +01:00
#include "options.h"
#include "win.h"
1999-03-14 17:35:05 +01:00
#include "windef.h"
1999-02-04 12:11:01 +01:00
#include "x11drv.h"
#include "xmalloc.h"
#include "version.h"
#include "win.h"
/**********************************************************************/
void X11DRV_USER_ParseOptions(int *argc, char *argv[]);
void X11DRV_USER_Create(void);
void X11DRV_USER_SaveSetup(void);
void X11DRV_USER_RestoreSetup(void);
1999-02-04 12:11:01 +01:00
/**********************************************************************/
#define WINE_CLASS "Wine" /* Class name for resources */
#define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
static XrmOptionDescRec optionsTable[] =
{
{ "-backingstore", ".backingstore", XrmoptionNoArg, (caddr_t)"on" },
{ "-desktop", ".desktop", XrmoptionSepArg, (caddr_t)NULL },
{ "-depth", ".depth", XrmoptionSepArg, (caddr_t)NULL },
{ "-display", ".display", XrmoptionSepArg, (caddr_t)NULL },
{ "-iconic", ".iconic", XrmoptionNoArg, (caddr_t)"on" },
{ "-language", ".language", XrmoptionSepArg, (caddr_t)"En" },
{ "-name", ".name", XrmoptionSepArg, (caddr_t)NULL },
{ "-perfect", ".perfect", XrmoptionNoArg, (caddr_t)"on" },
{ "-privatemap", ".privatemap", XrmoptionNoArg, (caddr_t)"on" },
{ "-fixedmap", ".fixedmap", XrmoptionNoArg, (caddr_t)"on" },
{ "-synchronous", ".synchronous", XrmoptionNoArg, (caddr_t)"on" },
{ "-debug", ".debug", XrmoptionNoArg, (caddr_t)"on" },
{ "-debugmsg", ".debugmsg", XrmoptionSepArg, (caddr_t)NULL },
{ "-dll", ".dll", XrmoptionSepArg, (caddr_t)NULL },
{ "-failreadonly", ".failreadonly", XrmoptionNoArg, (caddr_t)"on" },
{ "-mode", ".mode", XrmoptionSepArg, (caddr_t)NULL },
{ "-managed", ".managed", XrmoptionNoArg, (caddr_t)"off"},
{ "-winver", ".winver", XrmoptionSepArg, (caddr_t)NULL },
{ "-config", ".config", XrmoptionSepArg, (caddr_t)NULL },
{ "-nodga", ".nodga", XrmoptionNoArg, (caddr_t)"off"},
{ "-noxshm", ".noxshm", XrmoptionNoArg, (caddr_t)"off"},
1999-02-04 12:11:01 +01:00
{ "-console", ".console", XrmoptionSepArg, (caddr_t)NULL },
{ "-dosver", ".dosver", XrmoptionSepArg, (caddr_t)NULL }
};
#define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
/**********************************************************************/
static XKeyboardState X11DRV_XKeyboardState;
Display *display;
/***********************************************************************
* X11DRV_GetXScreen
*
* Return the X screen associated to the current desktop.
*/
Screen *X11DRV_GetXScreen()
{
return X11DRV_MONITOR_GetXScreen(&MONITOR_PrimaryMonitor);
}
/***********************************************************************
* X11DRV_GetXRootWindow
*
* Return the X display associated to the current desktop.
*/
Window X11DRV_GetXRootWindow()
{
return X11DRV_MONITOR_GetXRootWindow(&MONITOR_PrimaryMonitor);
}
/***********************************************************************
* X11DRV_USER_Initialize
1999-02-04 12:11:01 +01:00
*/
BOOL X11DRV_USER_Initialize(void)
1999-02-04 12:11:01 +01:00
{
CLIPBOARD_Driver = &X11DRV_CLIPBOARD_Driver;
DESKTOP_Driver = &X11DRV_DESKTOP_Driver;
EVENT_Driver = &X11DRV_EVENT_Driver;
KEYBOARD_Driver = &X11DRV_KEYBOARD_Driver;
MONITOR_Driver = &X11DRV_MONITOR_Driver;
MOUSE_Driver = &X11DRV_MOUSE_Driver;
WND_Driver = &X11DRV_WND_Driver;
1999-02-04 12:11:01 +01:00
/* We need this before calling any Xlib function */
InitializeCriticalSection( &X11DRV_CritSection );
MakeCriticalSectionGlobal( &X11DRV_CritSection );
TSXrmInitialize();
putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
X11DRV_USER_ParseOptions( Options.argc, Options.argv );
X11DRV_USER_Create();
X11DRV_USER_SaveSetup();
return TRUE;
1999-02-04 12:11:01 +01:00
}
/***********************************************************************
* X11DRV_USER_Finalize
*/
void X11DRV_USER_Finalize(void)
{
X11DRV_USER_RestoreSetup();
}
/**************************************************************************
* X11DRV_USER_BeginDebugging
*/
void X11DRV_USER_BeginDebugging(void)
{
TSXUngrabServer(display);
TSXFlush(display);
}
/**************************************************************************
* X11DRV_USER_EndDebugging
1999-02-04 12:11:01 +01:00
*/
void X11DRV_USER_EndDebugging(void)
1999-02-04 12:11:01 +01:00
{
}
/***********************************************************************
* X11DRV_USER_GetResource
1999-02-04 12:11:01 +01:00
*
* Fetch the value of resource 'name' using the correct instance name.
* 'name' must begin with '.' or '*'
*/
static int X11DRV_USER_GetResource( XrmDatabase db, char *name, XrmValue *value )
1999-02-04 12:11:01 +01:00
{
char *buff_instance, *buff_class;
char *dummy;
int retval;
buff_instance = (char *)xmalloc(strlen(Options.programName)+strlen(name)+1);
buff_class = (char *)xmalloc( strlen(WINE_CLASS) + strlen(name) + 1 );
strcpy( buff_instance, Options.programName );
strcat( buff_instance, name );
strcpy( buff_class, WINE_CLASS );
strcat( buff_class, name );
retval = TSXrmGetResource( db, buff_instance, buff_class, &dummy, value );
free( buff_instance );
free( buff_class );
return retval;
}
/***********************************************************************
* X11DRV_USER_ParseOptions
1999-02-04 12:11:01 +01:00
* Parse command line options and open display.
*/
void X11DRV_USER_ParseOptions(int *argc, char *argv[])
1999-02-04 12:11:01 +01:00
{
int i;
char *display_name = NULL;
XrmValue value;
XrmDatabase db = TSXrmGetFileDatabase(WINE_APP_DEFAULTS);
char *xrm_string;
/* Get display name from command line */
for (i = 1; i < *argc; i++)
{
if (!strcmp( argv[i], "-display" )) display_name = argv[i+1];
}
/* Open display */
if (display_name == NULL &&
X11DRV_USER_GetResource( db, ".display", &value )) display_name = value.addr;
1999-02-04 12:11:01 +01:00
if (!(display = TSXOpenDisplay( display_name )))
{
MESSAGE( "%s: Can't open display: %s\n",
1999-02-04 12:11:01 +01:00
argv[0], display_name ? display_name : "(none specified)" );
exit(1);
}
/* tell the libX11 that we will do input method handling ourselves
* that keep libX11 from doing anything whith dead keys, allowing Wine
* to have total control over dead keys, that is this line allows
* them to work in Wine, even whith a libX11 including the dead key
* patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
*/
TSXOpenIM(display,NULL,NULL,NULL);
/* Merge file and screen databases */
if ((xrm_string = TSXResourceManagerString( display )) != NULL)
{
XrmDatabase display_db = TSXrmGetStringDatabase( xrm_string );
TSXrmMergeDatabases( display_db, &db );
}
/* Parse command line */
TSXrmParseCommand( &db, optionsTable, NB_OPTIONS,
Options.programName, argc, argv );
/* Get all options */
if (X11DRV_USER_GetResource( db, ".iconic", &value ))
1999-02-04 12:11:01 +01:00
Options.cmdShow = SW_SHOWMINIMIZED;
if (X11DRV_USER_GetResource( db, ".privatemap", &value ))
1999-02-04 12:11:01 +01:00
Options.usePrivateMap = TRUE;
if (X11DRV_USER_GetResource( db, ".fixedmap", &value ))
1999-02-04 12:11:01 +01:00
Options.useFixedMap = TRUE;
if (X11DRV_USER_GetResource( db, ".synchronous", &value ))
1999-02-04 12:11:01 +01:00
Options.synchronous = TRUE;
if (X11DRV_USER_GetResource( db, ".backingstore", &value ))
1999-02-04 12:11:01 +01:00
Options.backingstore = TRUE;
if (X11DRV_USER_GetResource( db, ".debug", &value ))
1999-02-04 12:11:01 +01:00
Options.debug = TRUE;
if (X11DRV_USER_GetResource( db, ".failreadonly", &value ))
1999-02-04 12:11:01 +01:00
Options.failReadOnly = TRUE;
if (X11DRV_USER_GetResource( db, ".perfect", &value ))
1999-02-04 12:11:01 +01:00
Options.perfectGraphics = TRUE;
if (X11DRV_USER_GetResource( db, ".depth", &value))
1999-02-04 12:11:01 +01:00
Options.screenDepth = atoi( value.addr );
if (X11DRV_USER_GetResource( db, ".desktop", &value))
1999-02-04 12:11:01 +01:00
Options.desktopGeometry = value.addr;
if (X11DRV_USER_GetResource( db, ".language", &value))
1999-02-04 12:11:01 +01:00
MAIN_ParseLanguageOption( (char *)value.addr );
if (X11DRV_USER_GetResource( db, ".managed", &value))
1999-02-04 12:11:01 +01:00
Options.managed = TRUE;
if (X11DRV_USER_GetResource( db, ".mode", &value))
1999-02-04 12:11:01 +01:00
MAIN_ParseModeOption( (char *)value.addr );
if (X11DRV_USER_GetResource( db, ".debugoptions", &value))
1999-02-04 12:11:01 +01:00
MAIN_ParseDebugOptions((char*)value.addr);
if (X11DRV_USER_GetResource( db, ".debugmsg", &value))
1999-02-04 12:11:01 +01:00
{
#ifndef DEBUG_RUNTIME
MESSAGE("%s: Option \"-debugmsg\" not implemented.\n" \
1999-02-04 12:11:01 +01:00
" Recompile with DEBUG_RUNTIME in include/debugtools.h defined.\n",
argv[0]);
exit(1);
#else
MAIN_ParseDebugOptions((char*)value.addr);
#endif
}
if (X11DRV_USER_GetResource( db, ".dll", &value))
{
if (Options.dllFlags)
{
/* don't overwrite previous value. Should we
* automatically add the ',' between multiple DLLs ?
*/
MESSAGE("Only one -dll flag is allowed. Use ',' between multiple DLLs\n");
}
else Options.dllFlags = xstrdup((char *)value.addr);
}
1999-02-04 12:11:01 +01:00
if (X11DRV_USER_GetResource( db, ".winver", &value))
1999-02-04 12:11:01 +01:00
VERSION_ParseWinVersion( (char*)value.addr );
if (X11DRV_USER_GetResource( db, ".dosver", &value))
1999-02-04 12:11:01 +01:00
VERSION_ParseDosVersion( (char*)value.addr );
if (X11DRV_USER_GetResource( db, ".config", &value))
1999-02-04 12:11:01 +01:00
Options.configFileName = xstrdup((char *)value.addr);
if (X11DRV_USER_GetResource( db, ".nodga", &value))
1999-02-04 12:11:01 +01:00
Options.noDGA = TRUE;
if (X11DRV_USER_GetResource( db, ".noxshm", &value))
Options.noXSHM = TRUE;
if (X11DRV_USER_GetResource( db, ".console", &value))
driver.driver_list = xstrdup((char *)value.addr);
1999-02-04 12:11:01 +01:00
else
driver.driver_list = CONSOLE_DEFAULT_DRIVER;
1999-02-04 12:11:01 +01:00
}
/***********************************************************************
* X11DRV_USER_ErrorHandler
1999-02-04 12:11:01 +01:00
*/
static int X11DRV_USER_ErrorHandler(Display *display, XErrorEvent *error_evt)
1999-02-04 12:11:01 +01:00
{
1999-06-18 20:24:47 +02:00
DebugBreak(); /* force an entry in the debugger */
1999-02-04 12:11:01 +01:00
return 0;
}
/***********************************************************************
* X11DRV_USER_Create
1999-02-04 12:11:01 +01:00
*/
void X11DRV_USER_Create()
1999-02-04 12:11:01 +01:00
{
if (Options.synchronous) XSetErrorHandler( X11DRV_USER_ErrorHandler );
1999-02-04 12:11:01 +01:00
if (Options.desktopGeometry && Options.managed)
{
#if 0
MESSAGE( "%s: -managed and -desktop options cannot be used together\n",
1999-02-04 12:11:01 +01:00
Options.programName );
exit(1);
#else
Options.managed = FALSE;
#endif
}
}
/***********************************************************************
* X11DRV_USER_SaveSetup
1999-02-04 12:11:01 +01:00
*/
void X11DRV_USER_SaveSetup()
1999-02-04 12:11:01 +01:00
{
TSXGetKeyboardControl(display, &X11DRV_XKeyboardState);
}
/***********************************************************************
* X11DRV_USER_RestoreSetup
1999-02-04 12:11:01 +01:00
*/
void X11DRV_USER_RestoreSetup()
1999-02-04 12:11:01 +01:00
{
XKeyboardControl keyboard_value;
keyboard_value.key_click_percent = X11DRV_XKeyboardState.key_click_percent;
keyboard_value.bell_percent = X11DRV_XKeyboardState.bell_percent;
keyboard_value.bell_pitch = X11DRV_XKeyboardState.bell_pitch;
keyboard_value.bell_duration = X11DRV_XKeyboardState.bell_duration;
keyboard_value.auto_repeat_mode = X11DRV_XKeyboardState.global_auto_repeat;
XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
}
#endif /* X_DISPLAY_MISSING */