4 * Copyright 1998 Patrik Stridvall
10 #ifndef X_DISPLAY_MISSING
12 #include <X11/Xlocale.h>
14 #include "ts_xresource.h"
22 #include "clipboard.h"
24 #include "debugtools.h"
39 /**********************************************************************/
41 void X11DRV_USER_ParseOptions(int *argc
, char *argv
[]);
42 void X11DRV_USER_Create(void);
43 void X11DRV_USER_SaveSetup(void);
44 void X11DRV_USER_RestoreSetup(void);
46 /**********************************************************************/
48 #define WINE_CLASS "Wine" /* Class name for resources */
49 #define WINE_APP_DEFAULTS "/usr/lib/X11/app-defaults/Wine"
51 static XrmOptionDescRec optionsTable
[] =
53 { "-backingstore", ".backingstore", XrmoptionNoArg
, (caddr_t
)"on" },
54 { "-desktop", ".desktop", XrmoptionSepArg
, (caddr_t
)NULL
},
55 { "-depth", ".depth", XrmoptionSepArg
, (caddr_t
)NULL
},
56 { "-display", ".display", XrmoptionSepArg
, (caddr_t
)NULL
},
57 { "-iconic", ".iconic", XrmoptionNoArg
, (caddr_t
)"on" },
58 { "-language", ".language", XrmoptionSepArg
, (caddr_t
)"En" },
59 { "-name", ".name", XrmoptionSepArg
, (caddr_t
)NULL
},
60 { "-perfect", ".perfect", XrmoptionNoArg
, (caddr_t
)"on" },
61 { "-privatemap", ".privatemap", XrmoptionNoArg
, (caddr_t
)"on" },
62 { "-fixedmap", ".fixedmap", XrmoptionNoArg
, (caddr_t
)"on" },
63 { "-synchronous", ".synchronous", XrmoptionNoArg
, (caddr_t
)"on" },
64 { "-debug", ".debug", XrmoptionNoArg
, (caddr_t
)"on" },
65 { "-debugmsg", ".debugmsg", XrmoptionSepArg
, (caddr_t
)NULL
},
66 { "-dll", ".dll", XrmoptionSepArg
, (caddr_t
)NULL
},
67 { "-failreadonly", ".failreadonly", XrmoptionNoArg
, (caddr_t
)"on" },
68 { "-mode", ".mode", XrmoptionSepArg
, (caddr_t
)NULL
},
69 { "-managed", ".managed", XrmoptionNoArg
, (caddr_t
)"off"},
70 { "-winver", ".winver", XrmoptionSepArg
, (caddr_t
)NULL
},
71 { "-config", ".config", XrmoptionSepArg
, (caddr_t
)NULL
},
72 { "-nodga", ".nodga", XrmoptionNoArg
, (caddr_t
)"off"},
73 { "-noxshm", ".noxshm", XrmoptionNoArg
, (caddr_t
)"off"},
74 { "-console", ".console", XrmoptionSepArg
, (caddr_t
)NULL
},
75 { "-dosver", ".dosver", XrmoptionSepArg
, (caddr_t
)NULL
}
78 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
80 /**********************************************************************/
82 static XKeyboardState X11DRV_XKeyboardState
;
85 /***********************************************************************
88 * Return the X screen associated to the current desktop.
90 Screen
*X11DRV_GetXScreen()
92 return X11DRV_MONITOR_GetXScreen(&MONITOR_PrimaryMonitor
);
95 /***********************************************************************
96 * X11DRV_GetXRootWindow
98 * Return the X display associated to the current desktop.
100 Window
X11DRV_GetXRootWindow()
102 return X11DRV_MONITOR_GetXRootWindow(&MONITOR_PrimaryMonitor
);
105 /***********************************************************************
106 * X11DRV_USER_Initialize
108 BOOL
X11DRV_USER_Initialize(void)
110 CLIPBOARD_Driver
= &X11DRV_CLIPBOARD_Driver
;
111 DESKTOP_Driver
= &X11DRV_DESKTOP_Driver
;
112 EVENT_Driver
= &X11DRV_EVENT_Driver
;
113 KEYBOARD_Driver
= &X11DRV_KEYBOARD_Driver
;
114 MONITOR_Driver
= &X11DRV_MONITOR_Driver
;
115 MOUSE_Driver
= &X11DRV_MOUSE_Driver
;
116 WND_Driver
= &X11DRV_WND_Driver
;
118 /* We need this before calling any Xlib function */
119 InitializeCriticalSection( &X11DRV_CritSection
);
120 MakeCriticalSectionGlobal( &X11DRV_CritSection
);
124 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
126 X11DRV_USER_ParseOptions( Options
.argc
, Options
.argv
);
127 X11DRV_USER_Create();
128 X11DRV_USER_SaveSetup();
133 /***********************************************************************
134 * X11DRV_USER_Finalize
136 void X11DRV_USER_Finalize(void)
138 X11DRV_USER_RestoreSetup();
141 /**************************************************************************
142 * X11DRV_USER_BeginDebugging
144 void X11DRV_USER_BeginDebugging(void)
146 TSXUngrabServer(display
);
150 /**************************************************************************
151 * X11DRV_USER_EndDebugging
153 void X11DRV_USER_EndDebugging(void)
157 /***********************************************************************
158 * X11DRV_USER_GetResource
160 * Fetch the value of resource 'name' using the correct instance name.
161 * 'name' must begin with '.' or '*'
163 static int X11DRV_USER_GetResource( XrmDatabase db
, char *name
, XrmValue
*value
)
165 char *buff_instance
, *buff_class
;
169 buff_instance
= (char *)xmalloc(strlen(Options
.programName
)+strlen(name
)+1);
170 buff_class
= (char *)xmalloc( strlen(WINE_CLASS
) + strlen(name
) + 1 );
172 strcpy( buff_instance
, Options
.programName
);
173 strcat( buff_instance
, name
);
174 strcpy( buff_class
, WINE_CLASS
);
175 strcat( buff_class
, name
);
176 retval
= TSXrmGetResource( db
, buff_instance
, buff_class
, &dummy
, value
);
177 free( buff_instance
);
182 /***********************************************************************
183 * X11DRV_USER_ParseOptions
184 * Parse command line options and open display.
186 void X11DRV_USER_ParseOptions(int *argc
, char *argv
[])
189 char *display_name
= NULL
;
191 XrmDatabase db
= TSXrmGetFileDatabase(WINE_APP_DEFAULTS
);
194 /* Get display name from command line */
195 for (i
= 1; i
< *argc
; i
++)
197 if (!strcmp( argv
[i
], "-display" )) display_name
= argv
[i
+1];
202 if (display_name
== NULL
&&
203 X11DRV_USER_GetResource( db
, ".display", &value
)) display_name
= value
.addr
;
205 if (!(display
= TSXOpenDisplay( display_name
)))
207 MESSAGE( "%s: Can't open display: %s\n",
208 argv
[0], display_name
? display_name
: "(none specified)" );
212 /* tell the libX11 that we will do input method handling ourselves
213 * that keep libX11 from doing anything whith dead keys, allowing Wine
214 * to have total control over dead keys, that is this line allows
215 * them to work in Wine, even whith a libX11 including the dead key
216 * patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
218 TSXOpenIM(display
,NULL
,NULL
,NULL
);
220 /* Merge file and screen databases */
221 if ((xrm_string
= TSXResourceManagerString( display
)) != NULL
)
223 XrmDatabase display_db
= TSXrmGetStringDatabase( xrm_string
);
224 TSXrmMergeDatabases( display_db
, &db
);
227 /* Parse command line */
228 TSXrmParseCommand( &db
, optionsTable
, NB_OPTIONS
,
229 Options
.programName
, argc
, argv
);
231 /* Get all options */
232 if (X11DRV_USER_GetResource( db
, ".iconic", &value
))
233 Options
.cmdShow
= SW_SHOWMINIMIZED
;
234 if (X11DRV_USER_GetResource( db
, ".privatemap", &value
))
235 Options
.usePrivateMap
= TRUE
;
236 if (X11DRV_USER_GetResource( db
, ".fixedmap", &value
))
237 Options
.useFixedMap
= TRUE
;
238 if (X11DRV_USER_GetResource( db
, ".synchronous", &value
))
239 Options
.synchronous
= TRUE
;
240 if (X11DRV_USER_GetResource( db
, ".backingstore", &value
))
241 Options
.backingstore
= TRUE
;
242 if (X11DRV_USER_GetResource( db
, ".debug", &value
))
243 Options
.debug
= TRUE
;
244 if (X11DRV_USER_GetResource( db
, ".failreadonly", &value
))
245 Options
.failReadOnly
= TRUE
;
246 if (X11DRV_USER_GetResource( db
, ".perfect", &value
))
247 Options
.perfectGraphics
= TRUE
;
248 if (X11DRV_USER_GetResource( db
, ".depth", &value
))
249 Options
.screenDepth
= atoi( value
.addr
);
250 if (X11DRV_USER_GetResource( db
, ".desktop", &value
))
251 Options
.desktopGeometry
= value
.addr
;
252 if (X11DRV_USER_GetResource( db
, ".language", &value
))
253 MAIN_ParseLanguageOption( (char *)value
.addr
);
254 if (X11DRV_USER_GetResource( db
, ".managed", &value
))
255 Options
.managed
= TRUE
;
256 if (X11DRV_USER_GetResource( db
, ".mode", &value
))
257 MAIN_ParseModeOption( (char *)value
.addr
);
258 if (X11DRV_USER_GetResource( db
, ".debugoptions", &value
))
259 MAIN_ParseDebugOptions((char*)value
.addr
);
260 if (X11DRV_USER_GetResource( db
, ".debugmsg", &value
))
262 #ifndef DEBUG_RUNTIME
263 MESSAGE("%s: Option \"-debugmsg\" not implemented.\n" \
264 " Recompile with DEBUG_RUNTIME in include/debugtools.h defined.\n",
268 MAIN_ParseDebugOptions((char*)value
.addr
);
272 if (X11DRV_USER_GetResource( db
, ".dll", &value
))
274 if (Options
.dllFlags
)
276 /* don't overwrite previous value. Should we
277 * automatically add the ',' between multiple DLLs ?
279 MESSAGE("Only one -dll flag is allowed. Use ',' between multiple DLLs\n");
281 else Options
.dllFlags
= xstrdup((char *)value
.addr
);
284 if (X11DRV_USER_GetResource( db
, ".winver", &value
))
285 VERSION_ParseWinVersion( (char*)value
.addr
);
286 if (X11DRV_USER_GetResource( db
, ".dosver", &value
))
287 VERSION_ParseDosVersion( (char*)value
.addr
);
288 if (X11DRV_USER_GetResource( db
, ".config", &value
))
289 Options
.configFileName
= xstrdup((char *)value
.addr
);
290 if (X11DRV_USER_GetResource( db
, ".nodga", &value
))
291 Options
.noDGA
= TRUE
;
292 if (X11DRV_USER_GetResource( db
, ".noxshm", &value
))
293 Options
.noXSHM
= TRUE
;
294 if (X11DRV_USER_GetResource( db
, ".console", &value
))
295 driver
.driver_list
= xstrdup((char *)value
.addr
);
297 driver
.driver_list
= CONSOLE_DEFAULT_DRIVER
;
300 /***********************************************************************
301 * X11DRV_USER_ErrorHandler
303 static int X11DRV_USER_ErrorHandler(Display
*display
, XErrorEvent
*error_evt
)
305 DebugBreak(); /* force an entry in the debugger */
309 /***********************************************************************
312 void X11DRV_USER_Create()
314 if (Options
.synchronous
) XSetErrorHandler( X11DRV_USER_ErrorHandler
);
316 if (Options
.desktopGeometry
&& Options
.managed
)
319 MESSAGE( "%s: -managed and -desktop options cannot be used together\n",
320 Options
.programName
);
323 Options
.managed
= FALSE
;
328 /***********************************************************************
329 * X11DRV_USER_SaveSetup
331 void X11DRV_USER_SaveSetup()
333 TSXGetKeyboardControl(display
, &X11DRV_XKeyboardState
);
336 /***********************************************************************
337 * X11DRV_USER_RestoreSetup
339 void X11DRV_USER_RestoreSetup()
341 XKeyboardControl keyboard_value
;
343 keyboard_value
.key_click_percent
= X11DRV_XKeyboardState
.key_click_percent
;
344 keyboard_value
.bell_percent
= X11DRV_XKeyboardState
.bell_percent
;
345 keyboard_value
.bell_pitch
= X11DRV_XKeyboardState
.bell_pitch
;
346 keyboard_value
.bell_duration
= X11DRV_XKeyboardState
.bell_duration
;
347 keyboard_value
.auto_repeat_mode
= X11DRV_XKeyboardState
.global_auto_repeat
;
349 XChangeKeyboardControl(display
, KBKeyClickPercent
| KBBellPercent
|
350 KBBellPitch
| KBBellDuration
| KBAutoRepeatMode
, &keyboard_value
);
353 #endif /* X_DISPLAY_MISSING */