2 * X11DRV initialization code
4 * Copyright 1998 Patrik Stridvall
5 * Copyright 2000 Alexandre Julliard
13 #include <X11/cursorfont.h>
19 #include "wine/winbase16.h"
23 #include "debugtools.h"
31 DEFAULT_DEBUG_CHANNEL(x11drv);
33 static XKeyboardState keyboard_state;
38 unsigned int screen_width;
39 unsigned int screen_height;
40 unsigned int screen_depth;
43 /***********************************************************************
46 static int error_handler(Display *display, XErrorEvent *error_evt)
48 DebugBreak(); /* force an entry in the debugger */
53 /***********************************************************************
56 * Setup the x11drv options.
58 static void setup_options(void)
64 if (RegCreateKeyExA( HKEY_LOCAL_MACHINE, "Software\\Wine\\Wine\\Config\\x11drv", 0, NULL,
65 REG_OPTION_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, NULL ))
67 ERR("Cannot create config registry key\n" );
71 /* --display option */
73 count = sizeof(buffer);
74 if (!RegQueryValueExA( hkey, "display", 0, &type, buffer, &count ))
78 if (strcmp( buffer, Options.display ))
79 MESSAGE( "%s: warning: --display option ignored, using '%s'\n", argv0, buffer );
81 else if ((Options.display = getenv( "DISPLAY" )))
83 if (strcmp( buffer, Options.display ))
84 MESSAGE( "%s: warning: $DISPLAY variable ignored, using '%s'\n", argv0, buffer );
86 Options.display = strdup(buffer);
90 if (!Options.display && !(Options.display = getenv( "DISPLAY" )))
92 MESSAGE( "%s: no display specified\n", argv0 );
95 RegSetValueExA( hkey, "display", 0, REG_SZ, Options.display, strlen(Options.display)+1 );
98 /* --managed option */
100 if (!Options.managed)
102 count = sizeof(buffer);
103 if (!RegQueryValueExA( hkey, "managed", 0, &type, buffer, &count ))
104 Options.managed = IS_OPTION_TRUE( buffer[0] );
106 else RegSetValueExA( hkey, "managed", 0, REG_SZ, "y", 2 );
112 /***********************************************************************
115 * Create the desktop window for the --desktop mode.
117 static void create_desktop( const char *geometry )
119 int x = 0, y = 0, flags;
120 unsigned int width = 640, height = 480; /* Default size = 640x480 */
121 char *name = "Wine desktop";
122 XSizeHints *size_hints;
124 XClassHint *class_hints;
125 XSetWindowAttributes win_attr;
126 XTextProperty window_name;
127 Atom XA_WM_DELETE_WINDOW;
128 /* Used to create the desktop window with a good visual */
129 XVisualInfo *vi = NULL;
133 /* Get in wine.ini if the desktop window should have a double-buffered visual or not */
134 dblbuf_visual = PROFILE_GetWineIniBool( "x11drv", "DesktopDoubleBuffered", 0 );
136 int dblBuf[]={GLX_RGBA,GLX_DEPTH_SIZE,16,GLX_DOUBLEBUFFER,None};
139 vi = glXChooseVisual(display, DefaultScreen(display), dblBuf);
140 win_attr.colormap = XCreateColormap(display, RootWindow(display,vi->screen),
141 vi->visual, AllocNone);
144 #endif /* HAVE_OPENGL */
146 flags = TSXParseGeometry( geometry, &x, &y, &width, &height );
147 screen_width = width;
148 screen_height = height;
151 win_attr.background_pixel = BlackPixel(display, 0);
152 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
153 PointerMotionMask | ButtonPressMask |
154 ButtonReleaseMask | EnterWindowMask;
155 win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
159 screen = ScreenOfDisplay(display, vi->screen);
160 screen_depth = vi->depth;
162 root_window = TSXCreateWindow( display,
163 (vi == NULL ? DefaultRootWindow(display) : RootWindow(display, vi->screen)),
164 x, y, width, height, 0,
165 (vi == NULL ? CopyFromParent : vi->depth),
167 (vi == NULL ? CopyFromParent : vi->visual),
168 CWBackPixel | CWEventMask | CWCursor | (vi == NULL ? 0 : CWColormap),
171 /* Set window manager properties */
172 size_hints = TSXAllocSizeHints();
173 wm_hints = TSXAllocWMHints();
174 class_hints = TSXAllocClassHint();
175 if (!size_hints || !wm_hints || !class_hints)
177 MESSAGE("Not enough memory for window manager hints.\n" );
180 size_hints->min_width = size_hints->max_width = width;
181 size_hints->min_height = size_hints->max_height = height;
182 size_hints->flags = PMinSize | PMaxSize;
183 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
184 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
185 else size_hints->flags |= PSize;
187 wm_hints->flags = InputHint | StateHint;
188 wm_hints->input = True;
189 wm_hints->initial_state = NormalState;
190 class_hints->res_name = (char *)argv0;
191 class_hints->res_class = "Wine";
193 TSXStringListToTextProperty( &name, 1, &window_name );
194 TSXSetWMProperties( display, root_window, &window_name, &window_name,
195 NULL, 0, size_hints, wm_hints, class_hints );
196 XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
197 TSXSetWMProtocols( display, root_window, &XA_WM_DELETE_WINDOW, 1 );
198 TSXFree( size_hints );
200 TSXFree( class_hints );
203 TSXMapWindow( display, root_window );
206 /* Created so that XOpenIM can be called using the 'large stack' */
207 static void XOpenIM_large_stack(void)
209 TSXOpenIM(display,NULL,NULL,NULL);
212 /***********************************************************************
213 * X11DRV process initialisation routine
215 static void process_attach(void)
217 WND_Driver = &X11DRV_WND_Driver;
223 if (!(display = TSXOpenDisplay( Options.display )))
225 MESSAGE( "%s: Can't open display: %s\n", argv0, Options.display );
228 fcntl( ConnectionNumber(display), F_SETFD, 1 ); /* set close on exec flag */
229 screen = DefaultScreenOfDisplay( display );
230 visual = DefaultVisual( display, DefaultScreen(display) );
231 root_window = DefaultRootWindow( display );
233 /* Initialize screen depth */
235 screen_depth = PROFILE_GetWineIniInt( "x11drv", "ScreenDepth", 0 );
236 if (screen_depth) /* depth specified */
239 int *depth_list = TSXListDepths(display, DefaultScreen(display), &depth_count);
240 for (i = 0; i < depth_count; i++)
241 if (depth_list[i] == screen_depth) break;
242 TSXFree( depth_list );
243 if (i >= depth_count)
245 MESSAGE( "%s: Depth %d not supported on this screen.\n", argv0, screen_depth );
249 else screen_depth = DefaultDepthOfScreen( screen );
251 /* tell the libX11 that we will do input method handling ourselves
252 * that keep libX11 from doing anything whith dead keys, allowing Wine
253 * to have total control over dead keys, that is this line allows
254 * them to work in Wine, even whith a libX11 including the dead key
255 * patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
257 CALL_LARGE_STACK( XOpenIM_large_stack, NULL );
259 if (Options.synchronous) XSetErrorHandler( error_handler );
261 screen_width = WidthOfScreen( screen );
262 screen_height = HeightOfScreen( screen );
264 if (Options.desktopGeometry)
266 Options.managed = FALSE;
267 create_desktop( Options.desktopGeometry );
271 X11DRV_GDI_Initialize();
273 /* save keyboard setup */
274 TSXGetKeyboardControl(display, &keyboard_state);
276 /* initialize event handling */
279 /* load display.dll */
280 LoadLibrary16( "display" );
284 /***********************************************************************
285 * X11DRV process termination routine
287 static void process_detach(void)
289 /* restore keyboard setup */
290 XKeyboardControl keyboard_value;
292 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
293 keyboard_value.bell_percent = keyboard_state.bell_percent;
294 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
295 keyboard_value.bell_duration = keyboard_state.bell_duration;
296 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
298 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
299 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
302 X11DRV_GDI_Finalize();
306 /* close the display */
307 XCloseDisplay( display );
315 /***********************************************************************
316 * X11DRV initialisation routine
318 BOOL WINAPI X11DRV_Init( HINSTANCE hinst, DWORD reason, LPVOID reserved )
320 static int process_count;
324 case DLL_PROCESS_ATTACH:
325 if (!process_count++) process_attach();
327 case DLL_PROCESS_DETACH:
328 if (!--process_count) process_detach();
334 /***********************************************************************
335 * X11DRV_GetScreenSaveActive
337 * Returns the active status of the screen saver
339 BOOL X11DRV_GetScreenSaveActive(void)
342 TSXGetScreenSaver(display, &timeout, &temp, &temp, &temp);
346 /***********************************************************************
347 * X11DRV_SetScreenSaveActive
349 * Activate/Deactivate the screen saver
351 void X11DRV_SetScreenSaveActive(BOOL bActivate)
354 TSXActivateScreenSaver(display);
356 TSXResetScreenSaver(display);
359 /***********************************************************************
360 * X11DRV_GetScreenSaveTimeout
362 * Return the screen saver timeout
364 int X11DRV_GetScreenSaveTimeout(void)
367 TSXGetScreenSaver(display, &timeout, &temp, &temp, &temp);
371 /***********************************************************************
372 * X11DRV_SetScreenSaveTimeout
374 * Set the screen saver timeout
376 void X11DRV_SetScreenSaveTimeout(int nTimeout)
378 /* timeout is a 16bit entity (CARD16) in the protocol, so it should
379 * not get over 32767 or it will get negative. */
380 if (nTimeout>32767) nTimeout = 32767;
381 TSXSetScreenSaver(display, nTimeout, 60, DefaultBlanking, DefaultExposures);
384 /***********************************************************************
385 * X11DRV_IsSingleWindow
387 BOOL X11DRV_IsSingleWindow(void)
389 return (root_window != DefaultRootWindow(display));