DOSFS_ToDosFCBFormat: fail if extension longer than 3 characters.
[wine/gsoc-2012-control.git] / dlls / x11drv / x11drv_main.c
blob7b5ea3acd1d132afb65c362f853f4cc5a29d927d
1 /*
2 * X11DRV initialization code
4 * Copyright 1998 Patrik Stridvall
5 * Copyright 2000 Alexandre Julliard
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <X11/cursorfont.h>
11 #include "ts_xlib.h"
12 #include "ts_xutil.h"
14 #include "winbase.h"
16 #include "clipboard.h"
17 #include "debugtools.h"
18 #include "gdi.h"
19 #include "monitor.h"
20 #include "options.h"
21 #include "user.h"
22 #include "win.h"
23 #include "x11drv.h"
26 static USER_DRIVER user_driver =
28 /* event functions */
29 X11DRV_EVENT_Synchronize,
30 X11DRV_EVENT_CheckFocus,
31 X11DRV_EVENT_UserRepaintDisable,
32 /* keyboard functions */
33 X11DRV_KEYBOARD_Init,
34 X11DRV_KEYBOARD_VkKeyScan,
35 X11DRV_KEYBOARD_MapVirtualKey,
36 X11DRV_KEYBOARD_GetKeyNameText,
37 X11DRV_KEYBOARD_ToAscii,
38 X11DRV_KEYBOARD_GetBeepActive,
39 X11DRV_KEYBOARD_SetBeepActive,
40 X11DRV_KEYBOARD_Beep,
41 X11DRV_KEYBOARD_GetDIState,
42 X11DRV_KEYBOARD_GetDIData,
43 X11DRV_KEYBOARD_GetKeyboardConfig,
44 X11DRV_KEYBOARD_SetKeyboardConfig,
45 /* mouse functions */
46 X11DRV_MOUSE_Init,
47 X11DRV_MOUSE_SetCursor,
48 X11DRV_MOUSE_MoveCursor,
49 X11DRV_MOUSE_EnableWarpPointer,
50 /* screen saver functions */
51 X11DRV_GetScreenSaveActive,
52 X11DRV_SetScreenSaveActive,
53 X11DRV_GetScreenSaveTimeout,
54 X11DRV_SetScreenSaveTimeout,
55 /* windowing functions */
56 X11DRV_IsSingleWindow
59 static XKeyboardState keyboard_state;
61 Display *display;
62 Screen *screen;
63 Visual *visual;
64 int screen_depth;
65 Window root_window;
67 /***********************************************************************
68 * error_handler
70 static int error_handler(Display *display, XErrorEvent *error_evt)
72 DebugBreak(); /* force an entry in the debugger */
73 return 0;
77 /***********************************************************************
78 * create_desktop
80 * Create the desktop window for the --desktop mode.
82 static void create_desktop( const char *geometry )
84 int x = 0, y = 0, flags;
85 unsigned int width = 640, height = 480; /* Default size = 640x480 */
86 char *name = "Wine desktop";
87 XSizeHints *size_hints;
88 XWMHints *wm_hints;
89 XClassHint *class_hints;
90 XSetWindowAttributes win_attr;
91 XTextProperty window_name;
92 Atom XA_WM_DELETE_WINDOW;
94 flags = TSXParseGeometry( geometry, &x, &y, &width, &height );
95 MONITOR_PrimaryMonitor.rect.right = width;
96 MONITOR_PrimaryMonitor.rect.bottom = height;
98 /* Create window */
100 win_attr.background_pixel = BlackPixel(display, 0);
101 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
102 PointerMotionMask | ButtonPressMask |
103 ButtonReleaseMask | EnterWindowMask;
104 win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
106 root_window = TSXCreateWindow( display, DefaultRootWindow(display),
107 x, y, width, height, 0,
108 CopyFromParent, InputOutput, CopyFromParent,
109 CWBackPixel | CWEventMask | CWCursor, &win_attr);
111 /* Set window manager properties */
113 size_hints = TSXAllocSizeHints();
114 wm_hints = TSXAllocWMHints();
115 class_hints = TSXAllocClassHint();
116 if (!size_hints || !wm_hints || !class_hints)
118 MESSAGE("Not enough memory for window manager hints.\n" );
119 ExitProcess(1);
121 size_hints->min_width = size_hints->max_width = width;
122 size_hints->min_height = size_hints->max_height = height;
123 size_hints->flags = PMinSize | PMaxSize;
124 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
125 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
126 else size_hints->flags |= PSize;
128 wm_hints->flags = InputHint | StateHint;
129 wm_hints->input = True;
130 wm_hints->initial_state = NormalState;
131 class_hints->res_name = (char *)argv0;
132 class_hints->res_class = "Wine";
134 TSXStringListToTextProperty( &name, 1, &window_name );
135 TSXSetWMProperties( display, root_window, &window_name, &window_name,
136 Options.argv, Options.argc, size_hints, wm_hints, class_hints );
137 XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
138 TSXSetWMProtocols( display, root_window, &XA_WM_DELETE_WINDOW, 1 );
139 TSXFree( size_hints );
140 TSXFree( wm_hints );
141 TSXFree( class_hints );
143 /* Map window */
145 TSXMapWindow( display, root_window );
149 /***********************************************************************
150 * X11DRV process initialisation routine
152 static void process_attach(void)
154 USER_Driver = &user_driver;
155 CLIPBOARD_Driver = &X11DRV_CLIPBOARD_Driver;
156 WND_Driver = &X11DRV_WND_Driver;
158 /* We need this before calling any Xlib function */
159 InitializeCriticalSection( &X11DRV_CritSection );
160 MakeCriticalSectionGlobal( &X11DRV_CritSection );
162 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
164 /* Open display */
166 if (!(display = TSXOpenDisplay( Options.display )))
168 MESSAGE( "%s: Can't open display: %s\n",
169 argv0, Options.display ? Options.display : "(none specified)" );
170 ExitProcess(1);
172 screen = DefaultScreenOfDisplay( display );
173 visual = DefaultVisual( display, DefaultScreen(display) );
174 root_window = DefaultRootWindow( display );
176 /* Initialize screen depth */
178 screen_depth = PROFILE_GetWineIniInt( "x11drv", "ScreenDepth", 0 );
179 if (screen_depth) /* depth specified */
181 int depth_count, i;
182 int *depth_list = TSXListDepths(display, DefaultScreen(display), &depth_count);
183 for (i = 0; i < depth_count; i++)
184 if (depth_list[i] == screen_depth) break;
185 TSXFree( depth_list );
186 if (i >= depth_count)
188 MESSAGE( "%s: Depth %d not supported on this screen.\n", argv0, screen_depth );
189 ExitProcess(1);
192 else screen_depth = DefaultDepthOfScreen( screen );
194 /* tell the libX11 that we will do input method handling ourselves
195 * that keep libX11 from doing anything whith dead keys, allowing Wine
196 * to have total control over dead keys, that is this line allows
197 * them to work in Wine, even whith a libX11 including the dead key
198 * patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
200 TSXOpenIM(display,NULL,NULL,NULL);
202 if (Options.synchronous) XSetErrorHandler( error_handler );
204 MONITOR_PrimaryMonitor.rect.left = 0;
205 MONITOR_PrimaryMonitor.rect.top = 0;
206 MONITOR_PrimaryMonitor.rect.right = WidthOfScreen( screen );
207 MONITOR_PrimaryMonitor.rect.bottom = HeightOfScreen( screen );
208 MONITOR_PrimaryMonitor.depth = screen_depth;
210 if (Options.desktopGeometry)
212 Options.managed = FALSE;
213 create_desktop( Options.desktopGeometry );
216 /* initialize GDI */
217 X11DRV_GDI_Initialize();
219 /* save keyboard setup */
220 TSXGetKeyboardControl(display, &keyboard_state);
222 /* initialize event handling */
223 X11DRV_EVENT_Init();
227 /***********************************************************************
228 * X11DRV process termination routine
230 static void process_detach(void)
232 /* restore keyboard setup */
233 XKeyboardControl keyboard_value;
235 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
236 keyboard_value.bell_percent = keyboard_state.bell_percent;
237 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
238 keyboard_value.bell_duration = keyboard_state.bell_duration;
239 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
241 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
242 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
244 /* cleanup GDI */
245 X11DRV_GDI_Finalize();
247 #if 0 /* FIXME */
249 /* close the display */
250 XCloseDisplay( display );
251 display = NULL;
253 USER_Driver = NULL;
254 CLIPBOARD_Driver = NULL;
255 WND_Driver = NULL;
256 #endif
260 /***********************************************************************
261 * X11DRV initialisation routine
263 BOOL WINAPI X11DRV_Init( HINSTANCE hinst, DWORD reason, LPVOID reserved )
265 static int process_count;
267 switch(reason)
269 case DLL_PROCESS_ATTACH:
270 if (!process_count++) process_attach();
271 break;
272 case DLL_PROCESS_DETACH:
273 if (!--process_count) process_detach();
274 break;
276 return TRUE;
279 /***********************************************************************
280 * X11DRV_GetScreenSaveActive
282 * Returns the active status of the screen saver
284 BOOL X11DRV_GetScreenSaveActive(void)
286 int timeout, temp;
287 TSXGetScreenSaver(display, &timeout, &temp, &temp, &temp);
288 return timeout != NULL;
291 /***********************************************************************
292 * X11DRV_SetScreenSaveActive
294 * Activate/Deactivate the screen saver
296 void X11DRV_SetScreenSaveActive(BOOL bActivate)
298 if(bActivate)
299 TSXActivateScreenSaver(display);
300 else
301 TSXResetScreenSaver(display);
304 /***********************************************************************
305 * X11DRV_GetScreenSaveTimeout
307 * Return the screen saver timeout
309 int X11DRV_GetScreenSaveTimeout(void)
311 int timeout, temp;
312 TSXGetScreenSaver(display, &timeout, &temp, &temp, &temp);
313 return timeout;
316 /***********************************************************************
317 * X11DRV_SetScreenSaveTimeout
319 * Set the screen saver timeout
321 void X11DRV_SetScreenSaveTimeout(int nTimeout)
323 TSXSetScreenSaver(display, nTimeout, 60, DefaultBlanking, DefaultExposures);
326 /***********************************************************************
327 * X11DRV_IsSingleWindow
329 BOOL X11DRV_IsSingleWindow(void)
331 return (root_window != DefaultRootWindow(display));