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 { "-relaydbg", ".relaydbg", XrmoptionNoArg
, (caddr_t
)"on" }
60 #define NB_OPTIONS (sizeof(optionsTable) / sizeof(optionsTable[0]))
63 "Usage: %s [options] program_name [arguments]\n" \
66 " -depth n Change the depth to use for multiple-depth screens\n" \
67 " -desktop geom Use a desktop window of the given geometry\n" \
68 " -display name Use the specified display\n" \
69 " -iconic Start as an icon\n" \
70 " -name name Set the application name\n" \
71 " -privatemap Use a private color map\n" \
72 " -synchronous Turn on synchronous display mode\n" \
73 " -spy file Turn on message spying to the specified file\n" \
74 " -relaydbg Display call relay information\n"
77 /***********************************************************************
80 static void MAIN_Usage( char *name
)
82 fprintf( stderr
, USAGE
, name
);
87 /***********************************************************************
90 * Get the program name. The name is specified by (in order of precedence):
91 * - the option '-name'.
92 * - the environment variable 'WINE_NAME'.
93 * - the last component of argv[0].
95 static char *MAIN_GetProgramName( int argc
, char *argv
[] )
100 for (i
= 1; i
< argc
-1; i
++)
101 if (!strcmp( argv
[i
], "-name" )) return argv
[i
+1];
102 if ((p
= getenv( "WINE_NAME" )) != NULL
) return p
;
103 if ((p
= strrchr( argv
[0], '/' )) != NULL
) return p
+1;
108 /***********************************************************************
111 * Fetch the value of resource 'name' using the correct instance name.
112 * 'name' must begin with '.' or '*'
114 static int MAIN_GetResource( XrmDatabase db
, char *name
, XrmValue
*value
)
116 char *buff_instance
, *buff_class
;
120 buff_instance
= (char *)malloc(strlen(Options
.programName
)+strlen(name
)+1);
121 buff_class
= (char *)malloc( strlen(WINE_CLASS
) + strlen(name
) + 1 );
123 strcpy( buff_instance
, Options
.programName
);
124 strcat( buff_instance
, name
);
125 strcpy( buff_class
, WINE_CLASS
);
126 strcat( buff_class
, name
);
127 retval
= XrmGetResource( db
, buff_instance
, buff_class
, &dummy
, value
);
128 free( buff_instance
);
134 /***********************************************************************
137 * Parse command line options and open display.
139 static void MAIN_ParseOptions( int *argc
, char *argv
[] )
143 XrmDatabase db
= NULL
;
145 /* Parse command line */
147 Options
.programName
= MAIN_GetProgramName( *argc
, argv
);
148 XrmParseCommand( &db
, optionsTable
, NB_OPTIONS
,
149 Options
.programName
, argc
, argv
);
151 /* Need to assemble command line and pass it to WinMain */
153 if (*argc
< 2 || strcasecmp(argv
[1], "-h") == 0)
154 MAIN_Usage( argv
[0] );
159 if (MAIN_GetResource( db
, ".display", &value
)) display_name
= value
.addr
;
160 else display_name
= NULL
;
162 if (!(display
= XOpenDisplay( display_name
)))
164 fprintf( stderr
, "%s: Can't open display: %s\n",
165 argv
[0], display_name
? display_name
: "" );
169 /* Get all options */
171 if (MAIN_GetResource( db
, ".iconic", &value
))
172 Options
.cmdShow
= SW_SHOWMINIMIZED
;
173 if (MAIN_GetResource( db
, ".privatemap", &value
))
174 Options
.usePrivateMap
= TRUE
;
175 if (MAIN_GetResource( db
, ".synchronous", &value
))
176 Options
.synchronous
= TRUE
;
177 if (MAIN_GetResource( db
, ".relaydbg", &value
))
178 Options
.relay_debug
= TRUE
;
179 if (MAIN_GetResource( db
, ".spy", &value
))
180 Options
.spyFilename
= value
.addr
;
181 if (MAIN_GetResource( db
, ".depth", &value
))
182 screenDepth
= atoi( value
.addr
);
183 if (MAIN_GetResource( db
, ".desktop", &value
))
184 Options
.desktopGeometry
= value
.addr
;
188 /***********************************************************************
191 static void MAIN_CreateDesktop( int argc
, char *argv
[] )
194 unsigned int width
= 640, height
= 480; /* Default size = 640x480 */
195 char *name
= "Wine desktop";
196 XSizeHints size_hints
;
198 XClassHint class_hints
;
199 XSetWindowAttributes win_attr
;
200 XTextProperty window_name
;
202 flags
= XParseGeometry( Options
.desktopGeometry
,
203 &desktopX
, &desktopY
, &width
, &height
);
205 screenHeight
= height
;
209 win_attr
.event_mask
= ExposureMask
| KeyPressMask
| KeyReleaseMask
|
210 PointerMotionMask
| ButtonPressMask
|
211 ButtonReleaseMask
| EnterWindowMask
|
213 win_attr
.cursor
= XCreateFontCursor( display
, XC_top_left_arrow
);
215 rootWindow
= XCreateWindow( display
, DefaultRootWindow(display
),
216 desktopX
, desktopY
, width
, height
, 0,
217 CopyFromParent
, InputOutput
, CopyFromParent
,
218 CWEventMask
| CWCursor
, &win_attr
);
220 /* Set window manager properties */
222 size_hints
.min_width
= size_hints
.max_width
= width
;
223 size_hints
.min_height
= size_hints
.max_height
= height
;
224 size_hints
.flags
= PMinSize
| PMaxSize
;
225 if (flags
& (XValue
| YValue
)) size_hints
.flags
|= USPosition
;
226 if (flags
& (WidthValue
| HeightValue
)) size_hints
.flags
|= USSize
;
227 else size_hints
.flags
|= PSize
;
229 wm_hints
.flags
= InputHint
| StateHint
;
230 wm_hints
.input
= True
;
231 wm_hints
.initial_state
= NormalState
;
232 class_hints
.res_name
= argv
[0];
233 class_hints
.res_class
= "Wine";
235 XStringListToTextProperty( &name
, 1, &window_name
);
236 XSetWMProperties( display
, rootWindow
, &window_name
, &window_name
,
237 argv
, argc
, &size_hints
, &wm_hints
, &class_hints
);
241 XMapWindow( display
, rootWindow
);
245 XKeyboardState keyboard_state
;
247 /***********************************************************************
250 static void MAIN_SaveSetup(void)
252 XGetKeyboardControl(display
, &keyboard_state
);
255 /***********************************************************************
258 static void MAIN_RestoreSetup(void)
260 XKeyboardControl keyboard_value
;
262 keyboard_value
.key_click_percent
= keyboard_state
.key_click_percent
;
263 keyboard_value
.bell_percent
= keyboard_state
.bell_percent
;
264 keyboard_value
.bell_pitch
= keyboard_state
.bell_pitch
;
265 keyboard_value
.bell_duration
= keyboard_state
.bell_duration
;
266 keyboard_value
.auto_repeat_mode
= keyboard_state
.global_auto_repeat
;
268 XChangeKeyboardControl(display
, KBKeyClickPercent
| KBBellPercent
|
269 KBBellPitch
| KBBellDuration
| KBAutoRepeatMode
, &keyboard_value
);
272 static void called_at_exit(void)
279 /***********************************************************************
282 int main( int argc
, char *argv
[] )
290 MAIN_ParseOptions( &argc
, argv
);
292 screen
= DefaultScreenOfDisplay( display
);
293 screenWidth
= WidthOfScreen( screen
);
294 screenHeight
= HeightOfScreen( screen
);
295 XT_display
= display
;
297 if (screenDepth
) /* -depth option specified */
299 depth_list
= XListDepths(display
,DefaultScreen(display
),&depth_count
);
300 for (i
= 0; i
< depth_count
; i
++)
301 if (depth_list
[i
] == screenDepth
) break;
303 if (i
>= depth_count
)
305 fprintf( stderr
, "%s: Depth %d not supported on this screen.\n",
306 Options
.programName
, screenDepth
);
310 else screenDepth
= DefaultDepthOfScreen( screen
);
311 if (Options
.synchronous
) XSynchronize( display
, True
);
312 if (Options
.desktopGeometry
) MAIN_CreateDesktop( argc
, argv
);
313 else rootWindow
= DefaultRootWindow( display
);
315 ProgramName
= argv
[0];
321 atexit(called_at_exit
);
324 ret_val
= _WinMain( argc
, argv
);
333 /***********************************************************************
334 * MessageBeep (USER.104)
336 void MessageBeep(WORD i
)
341 /***********************************************************************
342 * GetVersion (KERNEL.3)
344 LONG
GetVersion(void)
346 return( 0x03300a03 ); /* dos 3.30 & win 3.10 */
349 /***********************************************************************
350 * GetWinFlags (KERNEL.132)
352 LONG
GetWinFlags(void)
354 return (WF_STANDARD
| WF_CPU286
| WF_PMODE
| WF_80x87
);
357 /***********************************************************************
358 * GetTimerResolution (USER.14)
360 LONG
GetTimerResolution(void)
365 /***********************************************************************
366 * SystemParametersInfo (USER.483)
368 BOOL
SystemParametersInfo (UINT uAction
, UINT uParam
, void FAR
*lpvParam
, UINT fuWinIni
)
372 XKeyboardState keyboard_state
;
373 XKeyboardControl keyboard_value
;
376 fprintf(stderr
, "SystemParametersInfo: action %d, param %x, flag %x\n",
377 uAction
, uParam
, fuWinIni
);
381 XGetKeyboardControl(display
, &keyboard_state
);
382 if (keyboard_state
.bell_percent
== 0)
383 *(BOOL
*) lpvParam
= FALSE
;
385 *(BOOL
*) lpvParam
= TRUE
;
389 *(INT
*) lpvParam
= 1;
392 case SPI_GETFASTTASKSWITCH
:
393 *(BOOL
*) lpvParam
= FALSE
;
396 case SPI_GETGRIDGRANULARITY
:
397 *(INT
*) lpvParam
= 1;
400 case SPI_GETICONTITLEWRAP
:
401 *(BOOL
*) lpvParam
= FALSE
;
404 case SPI_GETKEYBOARDDELAY
:
405 *(INT
*) lpvParam
= 1;
408 case SPI_GETKEYBOARDSPEED
:
409 *(WORD
*) lpvParam
= 30;
412 case SPI_GETMENUDROPALIGNMENT
:
413 *(BOOL
*) lpvParam
= FALSE
;
416 case SPI_GETSCREENSAVEACTIVE
:
417 *(BOOL
*) lpvParam
= FALSE
;
420 case SPI_GETSCREENSAVETIMEOUT
:
421 XGetScreenSaver(display
, &timeout
, &temp
,&temp
,&temp
);
422 *(INT
*) lpvParam
= timeout
* 1000;
425 case SPI_ICONHORIZONTALSPACING
:
426 if (lpvParam
== NULL
)
427 fprintf(stderr
, "SystemParametersInfo: Horizontal icon spacing set to %d\n.", uParam
);
429 *(INT
*) lpvParam
= 50;
432 case SPI_ICONVERTICALSPACING
:
433 if (lpvParam
== NULL
)
434 fprintf(stderr
, "SystemParametersInfo: Vertical icon spacing set to %d\n.", uParam
);
436 *(INT
*) lpvParam
= 50;
441 keyboard_value
.bell_percent
= -1;
443 keyboard_value
.bell_percent
= 0;
444 XChangeKeyboardControl(display
, KBBellPercent
,
448 case SPI_SETSCREENSAVEACTIVE
:
450 XActivateScreenSaver(display
);
452 XResetScreenSaver(display
);
455 case SPI_SETSCREENSAVETIMEOUT
:
456 XSetScreenSaver(display
, uParam
, 60, DefaultBlanking
,
460 case SPI_SETDESKWALLPAPER
:
461 return (SetDeskWallPaper((LPSTR
) lpvParam
));
464 case SPI_SETDESKPATTERN
:
465 if ((INT
) uParam
== -1) {
466 GetProfileString("Desktop", "Pattern",
467 "170 85 170 85 170 85 170 85",
468 buffer
, sizeof(buffer
) );
469 return (DESKTOP_SetPattern((LPSTR
) buffer
));
471 return (DESKTOP_SetPattern((LPSTR
) lpvParam
));
476 case SPI_SETDOUBLECLKHEIGHT
:
477 case SPI_SETDOUBLECLICKTIME
:
478 case SPI_SETDOUBLECLKWIDTH
:
479 case SPI_SETFASTTASKSWITCH
:
480 case SPI_SETKEYBOARDDELAY
:
481 case SPI_SETKEYBOARDSPEED
:
482 fprintf(stderr
, "SystemParametersInfo: option %d ignored.\n", uParam
);
486 fprintf(stderr
, "SystemParametersInfo: unknown option %d.\n", uParam
);
492 /***********************************************************************
493 * HMEMCPY (KERNEL.348)
495 void hmemcpy(void FAR
*hpvDest
, const void FAR
*hpvSource
, long cbCopy
)
501 copysize
= cbCopy
< 30000 ? cbCopy
: 30000;
503 memcpy(hpvDest
, hpvSource
, copysize
);
505 hpvSource
+= copysize
;
510 /***********************************************************************
513 void Copy(LPVOID lpSource
, LPVOID lpDest
, WORD nBytes
)
515 memcpy(lpDest
, lpSource
, nBytes
);