4 * Copyright 1994 Alexandre Julliard
7 static char Copyright
[] = "Copyright Alexandre Julliard, 1994";
13 #include <X11/Xresource.h>
14 #include <X11/Xutil.h>
15 #include <X11/cursorfont.h>
19 #include "prototypes.h"
21 #define WINE_CLASS "Wine" /* Class name for resources */
23 Display
* XT_display
; /* To be removed */
24 Screen
* XT_screen
; /* To be removed */
29 int screenWidth
= 0, screenHeight
= 0; /* Desktop window dimensions */
30 int screenDepth
= 0; /* Screen depth to use */
31 int desktopX
= 0, desktopY
= 0; /* Desktop window position (if any) */
33 char *ProgramName
; /* Used by resource.c with WINELIB */
35 struct options Options
=
36 { /* default options */
37 NULL
, /* spyFilename */
38 NULL
, /* desktopGeometry */
39 NULL
, /* programName */
40 FALSE
, /* usePrivateMap */
41 FALSE
, /* synchronous */
42 SW_SHOWNORMAL
, /* cmdShow */
47 static XrmOptionDescRec optionsTable
[] =
49 { "-desktop", ".desktop", XrmoptionSepArg
, (caddr_t
)NULL
},
50 { "-depth", ".depth", XrmoptionSepArg
, (caddr_t
)NULL
},
51 { "-display", ".display", XrmoptionSepArg
, (caddr_t
)NULL
},
52 { "-iconic", ".iconic", XrmoptionNoArg
, (caddr_t
)"on" },
53 { "-name", ".name", XrmoptionSepArg
, (caddr_t
)NULL
},
54 { "-privatemap", ".privatemap", XrmoptionNoArg
, (caddr_t
)"on" },
55 { "-synchronous", ".synchronous", XrmoptionNoArg
, (caddr_t
)"on" },
56 { "-spy", ".spy", XrmoptionSepArg
, (caddr_t
)NULL
},
57 { "-debug", ".debug", XrmoptionNoArg
, (caddr_t
)"on" },
58 { "-relaydbg", ".relaydbg", XrmoptionNoArg
, (caddr_t
)"on" }
61 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
64 "Usage: %s [options] program_name [arguments]\n" \
67 " -depth n Change the depth to use for multiple-depth screens\n" \
68 " -desktop geom Use a desktop window of the given geometry\n" \
69 " -display name Use the specified display\n" \
70 " -iconic Start as an icon\n" \
71 " -debug Enter debugger before starting application\n" \
72 " -name name Set the application name\n" \
73 " -privatemap Use a private color map\n" \
74 " -synchronous Turn on synchronous display mode\n" \
75 " -spy file Turn on message spying to the specified file\n" \
76 " -relaydbg Display call relay information\n"
79 /***********************************************************************
82 static void MAIN_Usage( char *name
)
84 fprintf( stderr
, USAGE
, name
);
89 /***********************************************************************
92 * Get the program name. The name is specified by (in order of precedence):
93 * - the option '-name'.
94 * - the environment variable 'WINE_NAME'.
95 * - the last component of argv[0].
97 static char *MAIN_GetProgramName( int argc
, char *argv
[] )
102 for (i
= 1; i
< argc
-1; i
++)
103 if (!strcmp( argv
[i
], "-name" )) return argv
[i
+1];
104 if ((p
= getenv( "WINE_NAME" )) != NULL
) return p
;
105 if ((p
= strrchr( argv
[0], '/' )) != NULL
) return p
+1;
110 /***********************************************************************
113 * Fetch the value of resource 'name' using the correct instance name.
114 * 'name' must begin with '.' or '*'
116 static int MAIN_GetResource( XrmDatabase db
, char *name
, XrmValue
*value
)
118 char *buff_instance
, *buff_class
;
122 buff_instance
= (char *)malloc(strlen(Options
.programName
)+strlen(name
)+1);
123 buff_class
= (char *)malloc( strlen(WINE_CLASS
) + strlen(name
) + 1 );
125 strcpy( buff_instance
, Options
.programName
);
126 strcat( buff_instance
, name
);
127 strcpy( buff_class
, WINE_CLASS
);
128 strcat( buff_class
, name
);
129 retval
= XrmGetResource( db
, buff_instance
, buff_class
, &dummy
, value
);
130 free( buff_instance
);
136 /***********************************************************************
139 * Parse command line options and open display.
141 static void MAIN_ParseOptions( int *argc
, char *argv
[] )
145 XrmDatabase db
= NULL
;
147 /* Parse command line */
149 Options
.programName
= MAIN_GetProgramName( *argc
, argv
);
150 XrmParseCommand( &db
, optionsTable
, NB_OPTIONS
,
151 Options
.programName
, argc
, argv
);
153 /* Need to assemble command line and pass it to WinMain */
155 if (*argc
< 2 || strcasecmp(argv
[1], "-h") == 0)
156 MAIN_Usage( argv
[0] );
161 if (MAIN_GetResource( db
, ".display", &value
)) display_name
= value
.addr
;
162 else display_name
= NULL
;
164 if (!(display
= XOpenDisplay( display_name
)))
166 fprintf( stderr
, "%s: Can't open display: %s\n",
167 argv
[0], display_name
? display_name
: "" );
171 /* Get all options */
173 if (MAIN_GetResource( db
, ".iconic", &value
))
174 Options
.cmdShow
= SW_SHOWMINIMIZED
;
175 if (MAIN_GetResource( db
, ".privatemap", &value
))
176 Options
.usePrivateMap
= TRUE
;
177 if (MAIN_GetResource( db
, ".synchronous", &value
))
178 Options
.synchronous
= TRUE
;
179 if (MAIN_GetResource( db
, ".relaydbg", &value
))
180 Options
.relay_debug
= TRUE
;
181 if (MAIN_GetResource( db
, ".debug", &value
))
182 Options
.debug
= TRUE
;
183 if (MAIN_GetResource( db
, ".spy", &value
))
184 Options
.spyFilename
= value
.addr
;
185 if (MAIN_GetResource( db
, ".depth", &value
))
186 screenDepth
= atoi( value
.addr
);
187 if (MAIN_GetResource( db
, ".desktop", &value
))
188 Options
.desktopGeometry
= value
.addr
;
192 /***********************************************************************
195 static void MAIN_CreateDesktop( int argc
, char *argv
[] )
198 unsigned int width
= 640, height
= 480; /* Default size = 640x480 */
199 char *name
= "Wine desktop";
200 XSizeHints size_hints
;
202 XClassHint class_hints
;
203 XSetWindowAttributes win_attr
;
204 XTextProperty window_name
;
206 flags
= XParseGeometry( Options
.desktopGeometry
,
207 &desktopX
, &desktopY
, &width
, &height
);
209 screenHeight
= height
;
213 win_attr
.event_mask
= ExposureMask
| KeyPressMask
| KeyReleaseMask
|
214 PointerMotionMask
| ButtonPressMask
|
215 ButtonReleaseMask
| EnterWindowMask
|
217 win_attr
.cursor
= XCreateFontCursor( display
, XC_top_left_arrow
);
219 rootWindow
= XCreateWindow( display
, DefaultRootWindow(display
),
220 desktopX
, desktopY
, width
, height
, 0,
221 CopyFromParent
, InputOutput
, CopyFromParent
,
222 CWEventMask
| CWCursor
, &win_attr
);
224 /* Set window manager properties */
226 size_hints
.min_width
= size_hints
.max_width
= width
;
227 size_hints
.min_height
= size_hints
.max_height
= height
;
228 size_hints
.flags
= PMinSize
| PMaxSize
;
229 if (flags
& (XValue
| YValue
)) size_hints
.flags
|= USPosition
;
230 if (flags
& (WidthValue
| HeightValue
)) size_hints
.flags
|= USSize
;
231 else size_hints
.flags
|= PSize
;
233 wm_hints
.flags
= InputHint
| StateHint
;
234 wm_hints
.input
= True
;
235 wm_hints
.initial_state
= NormalState
;
236 class_hints
.res_name
= argv
[0];
237 class_hints
.res_class
= "Wine";
239 XStringListToTextProperty( &name
, 1, &window_name
);
240 XSetWMProperties( display
, rootWindow
, &window_name
, &window_name
,
241 argv
, argc
, &size_hints
, &wm_hints
, &class_hints
);
245 XMapWindow( display
, rootWindow
);
249 XKeyboardState keyboard_state
;
251 /***********************************************************************
254 static void MAIN_SaveSetup(void)
256 XGetKeyboardControl(display
, &keyboard_state
);
259 /***********************************************************************
262 static void MAIN_RestoreSetup(void)
264 XKeyboardControl keyboard_value
;
266 keyboard_value
.key_click_percent
= keyboard_state
.key_click_percent
;
267 keyboard_value
.bell_percent
= keyboard_state
.bell_percent
;
268 keyboard_value
.bell_pitch
= keyboard_state
.bell_pitch
;
269 keyboard_value
.bell_duration
= keyboard_state
.bell_duration
;
270 keyboard_value
.auto_repeat_mode
= keyboard_state
.global_auto_repeat
;
272 XChangeKeyboardControl(display
, KBKeyClickPercent
| KBBellPercent
|
273 KBBellPitch
| KBBellDuration
| KBAutoRepeatMode
, &keyboard_value
);
276 static void called_at_exit(void)
284 /***********************************************************************
287 int main( int argc
, char *argv
[] )
295 MAIN_ParseOptions( &argc
, argv
);
297 screen
= DefaultScreenOfDisplay( display
);
298 screenWidth
= WidthOfScreen( screen
);
299 screenHeight
= HeightOfScreen( screen
);
300 XT_display
= display
;
302 if (screenDepth
) /* -depth option specified */
304 depth_list
= XListDepths(display
,DefaultScreen(display
),&depth_count
);
305 for (i
= 0; i
< depth_count
; i
++)
306 if (depth_list
[i
] == screenDepth
) break;
308 if (i
>= depth_count
)
310 fprintf( stderr
, "%s: Depth %d not supported on this screen.\n",
311 Options
.programName
, screenDepth
);
315 else screenDepth
= DefaultDepthOfScreen( screen
);
316 if (Options
.synchronous
) XSynchronize( display
, True
);
317 if (Options
.desktopGeometry
) MAIN_CreateDesktop( argc
, argv
);
318 else rootWindow
= DefaultRootWindow( display
);
320 ProgramName
= argv
[0];
326 atexit(called_at_exit
);
329 ret_val
= _WinMain( argc
, argv
);
338 /***********************************************************************
339 * MessageBeep (USER.104)
341 void MessageBeep(WORD i
)
346 /***********************************************************************
347 * GetVersion (KERNEL.3)
349 LONG
GetVersion(void)
351 return( 0x03300a03 ); /* dos 3.30 & win 3.10 */
354 /***********************************************************************
355 * GetWinFlags (KERNEL.132)
357 LONG
GetWinFlags(void)
359 return (WF_STANDARD
| WF_CPU286
| WF_PMODE
| WF_80x87
);
362 /***********************************************************************
363 * GetTimerResolution (USER.14)
365 LONG
GetTimerResolution(void)
370 /***********************************************************************
371 * SystemParametersInfo (USER.483)
373 BOOL
SystemParametersInfo (UINT uAction
, UINT uParam
, void FAR
*lpvParam
, UINT fuWinIni
)
377 XKeyboardState keyboard_state
;
378 XKeyboardControl keyboard_value
;
381 fprintf(stderr
, "SystemParametersInfo: action %d, param %x, flag %x\n",
382 uAction
, uParam
, fuWinIni
);
386 XGetKeyboardControl(display
, &keyboard_state
);
387 if (keyboard_state
.bell_percent
== 0)
388 *(BOOL
*) lpvParam
= FALSE
;
390 *(BOOL
*) lpvParam
= TRUE
;
394 *(INT
*) lpvParam
= 1;
397 case SPI_GETFASTTASKSWITCH
:
398 *(BOOL
*) lpvParam
= FALSE
;
401 case SPI_GETGRIDGRANULARITY
:
402 *(INT
*) lpvParam
= 1;
405 case SPI_GETICONTITLEWRAP
:
406 *(BOOL
*) lpvParam
= FALSE
;
409 case SPI_GETKEYBOARDDELAY
:
410 *(INT
*) lpvParam
= 1;
413 case SPI_GETKEYBOARDSPEED
:
414 *(WORD
*) lpvParam
= 30;
417 case SPI_GETMENUDROPALIGNMENT
:
418 *(BOOL
*) lpvParam
= FALSE
;
421 case SPI_GETSCREENSAVEACTIVE
:
422 *(BOOL
*) lpvParam
= FALSE
;
425 case SPI_GETSCREENSAVETIMEOUT
:
426 XGetScreenSaver(display
, &timeout
, &temp
,&temp
,&temp
);
427 *(INT
*) lpvParam
= timeout
* 1000;
430 case SPI_ICONHORIZONTALSPACING
:
431 if (lpvParam
== NULL
)
432 fprintf(stderr
, "SystemParametersInfo: Horizontal icon spacing set to %d\n.", uParam
);
434 *(INT
*) lpvParam
= 50;
437 case SPI_ICONVERTICALSPACING
:
438 if (lpvParam
== NULL
)
439 fprintf(stderr
, "SystemParametersInfo: Vertical icon spacing set to %d\n.", uParam
);
441 *(INT
*) lpvParam
= 50;
446 keyboard_value
.bell_percent
= -1;
448 keyboard_value
.bell_percent
= 0;
449 XChangeKeyboardControl(display
, KBBellPercent
,
453 case SPI_SETSCREENSAVEACTIVE
:
455 XActivateScreenSaver(display
);
457 XResetScreenSaver(display
);
460 case SPI_SETSCREENSAVETIMEOUT
:
461 XSetScreenSaver(display
, uParam
, 60, DefaultBlanking
,
465 case SPI_SETDESKWALLPAPER
:
466 return (SetDeskWallPaper((LPSTR
) lpvParam
));
469 case SPI_SETDESKPATTERN
:
470 if ((INT
) uParam
== -1) {
471 GetProfileString("Desktop", "Pattern",
472 "170 85 170 85 170 85 170 85",
473 buffer
, sizeof(buffer
) );
474 return (DESKTOP_SetPattern((LPSTR
) buffer
));
476 return (DESKTOP_SetPattern((LPSTR
) lpvParam
));
481 case SPI_SETDOUBLECLKHEIGHT
:
482 case SPI_SETDOUBLECLICKTIME
:
483 case SPI_SETDOUBLECLKWIDTH
:
484 case SPI_SETFASTTASKSWITCH
:
485 case SPI_SETKEYBOARDDELAY
:
486 case SPI_SETKEYBOARDSPEED
:
487 fprintf(stderr
, "SystemParametersInfo: option %d ignored.\n", uParam
);
491 fprintf(stderr
, "SystemParametersInfo: unknown option %d.\n", uParam
);
497 /***********************************************************************
498 * HMEMCPY (KERNEL.348)
500 void hmemcpy(void FAR
*hpvDest
, const void FAR
*hpvSource
, long cbCopy
)
502 memcpy(hpvDest
, hpvSource
, cbCopy
);
505 /***********************************************************************
508 void Copy(LPVOID lpSource
, LPVOID lpDest
, WORD nBytes
)
510 memcpy(lpDest
, lpSource
, nBytes
);
513 /***********************************************************************
514 * SWAPMOUSEBUTTON (USER.186)
516 BOOL
SwapMouseButton(BOOL fSwap
)
518 return 0; /* don't swap */