2 * X11DRV initialization code
4 * Copyright 1998 Patrik Stridvall
5 * Copyright 2000 Alexandre Julliard
10 #include <X11/cursorfont.h>
16 #include "clipboard.h"
17 #include "debugtools.h"
26 static USER_DRIVER user_driver
=
29 X11DRV_EVENT_Synchronize
,
30 X11DRV_EVENT_CheckFocus
,
31 X11DRV_EVENT_UserRepaintDisable
,
32 /* keyboard functions */
34 X11DRV_KEYBOARD_VkKeyScan
,
35 X11DRV_KEYBOARD_MapVirtualKey
,
36 X11DRV_KEYBOARD_GetKeyNameText
,
37 X11DRV_KEYBOARD_ToAscii
,
38 X11DRV_KEYBOARD_GetBeepActive
,
39 X11DRV_KEYBOARD_SetBeepActive
,
41 X11DRV_KEYBOARD_GetDIState
,
42 X11DRV_KEYBOARD_GetDIData
,
43 X11DRV_KEYBOARD_GetKeyboardConfig
,
44 X11DRV_KEYBOARD_SetKeyboardConfig
,
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 */
59 static XKeyboardState keyboard_state
;
67 /***********************************************************************
70 static int error_handler(Display
*display
, XErrorEvent
*error_evt
)
72 DebugBreak(); /* force an entry in the debugger */
77 /***********************************************************************
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
;
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
;
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" );
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
);
141 TSXFree( class_hints
);
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. */
166 if (!(display
= TSXOpenDisplay( Options
.display
)))
168 MESSAGE( "%s: Can't open display: %s\n",
169 argv0
, Options
.display
? Options
.display
: "(none specified)" );
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 */
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
);
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
);
217 X11DRV_GDI_Initialize();
219 /* save keyboard setup */
220 TSXGetKeyboardControl(display
, &keyboard_state
);
222 /* initialize event handling */
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
);
245 X11DRV_GDI_Finalize();
249 /* close the display */
250 XCloseDisplay( display
);
254 CLIPBOARD_Driver
= NULL
;
260 /***********************************************************************
261 * X11DRV initialisation routine
263 BOOL WINAPI
X11DRV_Init( HINSTANCE hinst
, DWORD reason
, LPVOID reserved
)
265 static int process_count
;
269 case DLL_PROCESS_ATTACH
:
270 if (!process_count
++) process_attach();
272 case DLL_PROCESS_DETACH
:
273 if (!--process_count
) process_detach();
279 /***********************************************************************
280 * X11DRV_GetScreenSaveActive
282 * Returns the active status of the screen saver
284 BOOL
X11DRV_GetScreenSaveActive(void)
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
)
299 TSXActivateScreenSaver(display
);
301 TSXResetScreenSaver(display
);
304 /***********************************************************************
305 * X11DRV_GetScreenSaveTimeout
307 * Return the screen saver timeout
309 int X11DRV_GetScreenSaveTimeout(void)
312 TSXGetScreenSaver(display
, &timeout
, &temp
, &temp
, &temp
);
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
));