2 * X11DRV initialization code
4 * Copyright 1998 Patrik Stridvall
5 * Copyright 2000 Alexandre Julliard
11 #include <X11/cursorfont.h>
17 #include "clipboard.h"
18 #include "debugtools.h"
27 static USER_DRIVER user_driver =
30 X11DRV_EVENT_Synchronize,
31 X11DRV_EVENT_CheckFocus,
32 X11DRV_EVENT_UserRepaintDisable,
33 /* keyboard functions */
35 X11DRV_KEYBOARD_VkKeyScan,
36 X11DRV_KEYBOARD_MapVirtualKey,
37 X11DRV_KEYBOARD_GetKeyNameText,
38 X11DRV_KEYBOARD_ToAscii,
39 X11DRV_KEYBOARD_GetBeepActive,
40 X11DRV_KEYBOARD_SetBeepActive,
42 X11DRV_KEYBOARD_GetDIState,
43 X11DRV_KEYBOARD_GetDIData,
44 X11DRV_KEYBOARD_GetKeyboardConfig,
45 X11DRV_KEYBOARD_SetKeyboardConfig,
48 X11DRV_MOUSE_SetCursor,
49 X11DRV_MOUSE_MoveCursor,
50 X11DRV_MOUSE_EnableWarpPointer,
51 /* screen saver functions */
52 X11DRV_GetScreenSaveActive,
53 X11DRV_SetScreenSaveActive,
54 X11DRV_GetScreenSaveTimeout,
55 X11DRV_SetScreenSaveTimeout,
56 /* windowing functions */
60 static XKeyboardState keyboard_state;
68 /***********************************************************************
71 static int error_handler(Display *display, XErrorEvent *error_evt)
73 DebugBreak(); /* force an entry in the debugger */
78 /***********************************************************************
81 * Create the desktop window for the --desktop mode.
83 static void create_desktop( const char *geometry )
85 int x = 0, y = 0, flags;
86 unsigned int width = 640, height = 480; /* Default size = 640x480 */
87 char *name = "Wine desktop";
88 XSizeHints *size_hints;
90 XClassHint *class_hints;
91 XSetWindowAttributes win_attr;
92 XTextProperty window_name;
93 Atom XA_WM_DELETE_WINDOW;
95 flags = TSXParseGeometry( geometry, &x, &y, &width, &height );
96 MONITOR_PrimaryMonitor.rect.right = width;
97 MONITOR_PrimaryMonitor.rect.bottom = height;
101 win_attr.background_pixel = BlackPixel(display, 0);
102 win_attr.event_mask = ExposureMask | KeyPressMask | KeyReleaseMask |
103 PointerMotionMask | ButtonPressMask |
104 ButtonReleaseMask | EnterWindowMask;
105 win_attr.cursor = TSXCreateFontCursor( display, XC_top_left_arrow );
107 root_window = TSXCreateWindow( display, DefaultRootWindow(display),
108 x, y, width, height, 0,
109 CopyFromParent, InputOutput, CopyFromParent,
110 CWBackPixel | CWEventMask | CWCursor, &win_attr);
112 /* Set window manager properties */
114 size_hints = TSXAllocSizeHints();
115 wm_hints = TSXAllocWMHints();
116 class_hints = TSXAllocClassHint();
117 if (!size_hints || !wm_hints || !class_hints)
119 MESSAGE("Not enough memory for window manager hints.\n" );
122 size_hints->min_width = size_hints->max_width = width;
123 size_hints->min_height = size_hints->max_height = height;
124 size_hints->flags = PMinSize | PMaxSize;
125 if (flags & (XValue | YValue)) size_hints->flags |= USPosition;
126 if (flags & (WidthValue | HeightValue)) size_hints->flags |= USSize;
127 else size_hints->flags |= PSize;
129 wm_hints->flags = InputHint | StateHint;
130 wm_hints->input = True;
131 wm_hints->initial_state = NormalState;
132 class_hints->res_name = (char *)argv0;
133 class_hints->res_class = "Wine";
135 TSXStringListToTextProperty( &name, 1, &window_name );
136 TSXSetWMProperties( display, root_window, &window_name, &window_name,
137 Options.argv, Options.argc, size_hints, wm_hints, class_hints );
138 XA_WM_DELETE_WINDOW = TSXInternAtom( display, "WM_DELETE_WINDOW", False );
139 TSXSetWMProtocols( display, root_window, &XA_WM_DELETE_WINDOW, 1 );
140 TSXFree( size_hints );
142 TSXFree( class_hints );
146 TSXMapWindow( display, root_window );
150 /***********************************************************************
151 * X11DRV process initialisation routine
153 static void process_attach(void)
155 USER_Driver = &user_driver;
156 CLIPBOARD_Driver = &X11DRV_CLIPBOARD_Driver;
157 WND_Driver = &X11DRV_WND_Driver;
161 if (!(display = TSXOpenDisplay( Options.display )))
163 MESSAGE( "%s: Can't open display: %s\n",
164 argv0, Options.display ? Options.display : "(none specified)" );
167 fcntl( ConnectionNumber(display), F_SETFD, 1 ); /* set close on exec flag */
168 screen = DefaultScreenOfDisplay( display );
169 visual = DefaultVisual( display, DefaultScreen(display) );
170 root_window = DefaultRootWindow( display );
172 /* Initialize screen depth */
174 screen_depth = PROFILE_GetWineIniInt( "x11drv", "ScreenDepth", 0 );
175 if (screen_depth) /* depth specified */
178 int *depth_list = TSXListDepths(display, DefaultScreen(display), &depth_count);
179 for (i = 0; i < depth_count; i++)
180 if (depth_list[i] == screen_depth) break;
181 TSXFree( depth_list );
182 if (i >= depth_count)
184 MESSAGE( "%s: Depth %d not supported on this screen.\n", argv0, screen_depth );
188 else screen_depth = DefaultDepthOfScreen( screen );
190 /* tell the libX11 that we will do input method handling ourselves
191 * that keep libX11 from doing anything whith dead keys, allowing Wine
192 * to have total control over dead keys, that is this line allows
193 * them to work in Wine, even whith a libX11 including the dead key
194 * patches from Th.Quinot (http://Web.FdN.FR/~tquinot/dead-keys.en.html)
196 TSXOpenIM(display,NULL,NULL,NULL);
198 if (Options.synchronous) XSetErrorHandler( error_handler );
200 MONITOR_PrimaryMonitor.rect.left = 0;
201 MONITOR_PrimaryMonitor.rect.top = 0;
202 MONITOR_PrimaryMonitor.rect.right = WidthOfScreen( screen );
203 MONITOR_PrimaryMonitor.rect.bottom = HeightOfScreen( screen );
204 MONITOR_PrimaryMonitor.depth = screen_depth;
206 if (Options.desktopGeometry)
208 Options.managed = FALSE;
209 create_desktop( Options.desktopGeometry );
213 X11DRV_GDI_Initialize();
215 /* save keyboard setup */
216 TSXGetKeyboardControl(display, &keyboard_state);
218 /* initialize event handling */
223 /***********************************************************************
224 * X11DRV process termination routine
226 static void process_detach(void)
228 /* restore keyboard setup */
229 XKeyboardControl keyboard_value;
231 keyboard_value.key_click_percent = keyboard_state.key_click_percent;
232 keyboard_value.bell_percent = keyboard_state.bell_percent;
233 keyboard_value.bell_pitch = keyboard_state.bell_pitch;
234 keyboard_value.bell_duration = keyboard_state.bell_duration;
235 keyboard_value.auto_repeat_mode = keyboard_state.global_auto_repeat;
237 XChangeKeyboardControl(display, KBKeyClickPercent | KBBellPercent |
238 KBBellPitch | KBBellDuration | KBAutoRepeatMode, &keyboard_value);
241 X11DRV_GDI_Finalize();
245 /* close the display */
246 XCloseDisplay( display );
250 CLIPBOARD_Driver = NULL;
256 /***********************************************************************
257 * X11DRV initialisation routine
259 BOOL WINAPI X11DRV_Init( HINSTANCE hinst, DWORD reason, LPVOID reserved )
261 static int process_count;
265 case DLL_PROCESS_ATTACH:
266 if (!process_count++) process_attach();
268 case DLL_PROCESS_DETACH:
269 if (!--process_count) process_detach();
275 /***********************************************************************
276 * X11DRV_GetScreenSaveActive
278 * Returns the active status of the screen saver
280 BOOL X11DRV_GetScreenSaveActive(void)
283 TSXGetScreenSaver(display, &timeout, &temp, &temp, &temp);
284 return timeout != NULL;
287 /***********************************************************************
288 * X11DRV_SetScreenSaveActive
290 * Activate/Deactivate the screen saver
292 void X11DRV_SetScreenSaveActive(BOOL bActivate)
295 TSXActivateScreenSaver(display);
297 TSXResetScreenSaver(display);
300 /***********************************************************************
301 * X11DRV_GetScreenSaveTimeout
303 * Return the screen saver timeout
305 int X11DRV_GetScreenSaveTimeout(void)
308 TSXGetScreenSaver(display, &timeout, &temp, &temp, &temp);
312 /***********************************************************************
313 * X11DRV_SetScreenSaveTimeout
315 * Set the screen saver timeout
317 void X11DRV_SetScreenSaveTimeout(int nTimeout)
319 TSXSetScreenSaver(display, nTimeout, 60, DefaultBlanking, DefaultExposures);
322 /***********************************************************************
323 * X11DRV_IsSingleWindow
325 BOOL X11DRV_IsSingleWindow(void)
327 return (root_window != DefaultRootWindow(display));