2 * X11DRV initialization code
4 * Copyright 1998 Patrik Stridvall
5 * Copyright 2000 Alexandre Julliard
14 #include "clipboard.h"
15 #include "debugtools.h"
24 static USER_DRIVER user_driver =
27 X11DRV_EVENT_Synchronize,
28 X11DRV_EVENT_CheckFocus,
29 X11DRV_EVENT_UserRepaintDisable,
30 /* keyboard functions */
32 X11DRV_KEYBOARD_VkKeyScan,
33 X11DRV_KEYBOARD_MapVirtualKey,
34 X11DRV_KEYBOARD_GetKeyNameText,
35 X11DRV_KEYBOARD_ToAscii,
36 X11DRV_KEYBOARD_GetBeepActive,
37 X11DRV_KEYBOARD_SetBeepActive,
39 X11DRV_KEYBOARD_GetDIState,
40 X11DRV_KEYBOARD_GetDIData,
41 X11DRV_KEYBOARD_GetKeyboardConfig,
42 X11DRV_KEYBOARD_SetKeyboardConfig,
45 X11DRV_MOUSE_SetCursor,
46 X11DRV_MOUSE_MoveCursor,
47 X11DRV_MOUSE_EnableWarpPointer
50 static XKeyboardState keyboard_state;
58 /***********************************************************************
61 static int error_handler(Display *display, XErrorEvent *error_evt)
63 DebugBreak(); /* force an entry in the debugger */
68 /***********************************************************************
69 * X11DRV process initialisation routine
71 static void process_attach(void)
73 USER_Driver = &user_driver;
74 CLIPBOARD_Driver = &X11DRV_CLIPBOARD_Driver;
75 MONITOR_Driver = &X11DRV_MONITOR_Driver;
76 WND_Driver = &X11DRV_WND_Driver;
78 /* We need this before calling any Xlib function */
79 InitializeCriticalSection( &X11DRV_CritSection );
80 MakeCriticalSectionGlobal( &X11DRV_CritSection );
82 putenv("XKB_DISABLE="); /* Disable XKB extension if present. */
86 if (!(display = TSXOpenDisplay( Options.display )))
88 MESSAGE( "%s: Can't open display: %s\n",
89 argv0, Options.display ? Options.display : "(none specified)" );
92 screen = DefaultScreenOfDisplay( display );
93 visual = DefaultVisual( display, DefaultScreen(display) );
94 root_window = DefaultRootWindow( display );
96 /* Initialize screen depth */
98 screen_depth = PROFILE_GetWineIniInt( "x11drv", "ScreenDepth", 0 );
99 if (screen_depth) /* depth specified */
102 int *depth_list = TSXListDepths(display, DefaultScreen(display), &depth_count);
103 for (i = 0; i < depth_count; i++)
104 if (depth_list[i] == screen_depth) break;
105 TSXFree( depth_list );
106 if (i >= depth_count)
108 MESSAGE( "%s: Depth %d not supported on this screen.\n", argv0, screen_depth );
112 else screen_depth = DefaultDepthOfScreen( screen );
114 /* tell the libX11 that we will do input method handling ourselves
115 * that keep libX11 from doing anything whith dead keys, allowing Wine
116 * to have total control over dead keys, that is this line allows
117 * them to work in Wine, even whith a libX11 including the dead key
118 * patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
120 TSXOpenIM(display,NULL,NULL,NULL);
122 if (Options.synchronous) XSetErrorHandler( error_handler );
123 if (Options.desktopGeometry && Options.managed) Options.managed = FALSE;
125 /* initialize monitor */
126 X11DRV_MONITOR_Initialize( &MONITOR_PrimaryMonitor );
129 X11DRV_GDI_Initialize();
131 /* save keyboard setup */
132 TSXGetKeyboardControl(display, &keyboard_state);
134 /* initialize event handling */
139 /***********************************************************************
140 * X11DRV process termination routine
142 static void process_detach(void)
144 /* restore keyboard setup */
145 XKeyboardControl keyboard_value;
147 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
148 keyboard_value.bell_percent = keyboard_state.bell_percent;
149 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
150 keyboard_value.bell_duration = keyboard_state.bell_duration;
151 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
153 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
154 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
157 X11DRV_GDI_Finalize();
161 /* cleanup monitor */
162 X11DRV_MONITOR_Finalize( &MONITOR_PrimaryMonitor );
164 /* close the display */
165 XCloseDisplay( display );
169 CLIPBOARD_Driver = NULL;
170 MONITOR_Driver = NULL;
176 /***********************************************************************
177 * X11DRV initialisation routine
179 BOOL WINAPI X11DRV_Init( HINSTANCE hinst, DWORD reason, LPVOID reserved )
181 static int process_count;
185 case DLL_PROCESS_ATTACH:
186 if (!process_count++) process_attach();
188 case DLL_PROCESS_DETACH:
189 if (!--process_count) process_detach();