2000-03-19 13:08:09 +01:00
|
|
|
/*
|
|
|
|
* X11DRV initialization code
|
2000-03-20 19:21:19 +01:00
|
|
|
*
|
|
|
|
* Copyright 1998 Patrik Stridvall
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-03-19 13:08:09 +01:00
|
|
|
*/
|
2000-03-20 19:21:19 +01:00
|
|
|
|
2000-05-24 01:38:32 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2000-04-04 21:57:23 +02:00
|
|
|
#include <fcntl.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-03-19 13:08:09 +01:00
|
|
|
#include <stdio.h>
|
2000-03-20 19:21:19 +01:00
|
|
|
#include <stdlib.h>
|
2000-11-12 04:41:47 +01:00
|
|
|
#include <string.h>
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2000-03-25 18:30:13 +01:00
|
|
|
#include <X11/cursorfont.h>
|
2003-11-21 22:50:59 +01:00
|
|
|
#include <X11/Xlib.h>
|
2003-03-23 21:07:55 +01:00
|
|
|
#ifdef HAVE_XKB
|
|
|
|
#include <X11/XKBlib.h>
|
|
|
|
#endif
|
2000-03-19 13:08:09 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-03-19 13:08:09 +01:00
|
|
|
#include "winbase.h"
|
2000-06-07 04:16:47 +02:00
|
|
|
#include "wine/winbase16.h"
|
2000-05-15 04:46:44 +02:00
|
|
|
#include "winreg.h"
|
2000-03-20 19:21:19 +01:00
|
|
|
|
2000-03-19 13:08:09 +01:00
|
|
|
#include "x11drv.h"
|
2001-02-14 01:27:34 +01:00
|
|
|
#include "xvidmode.h"
|
2003-10-16 02:21:42 +02:00
|
|
|
#include "xrandr.h"
|
2001-04-16 21:54:07 +02:00
|
|
|
#include "dga2.h"
|
2002-05-30 22:40:02 +02:00
|
|
|
#include "wine/server.h"
|
|
|
|
#include "wine/debug.h"
|
2000-03-19 13:08:09 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(x11drv);
|
2000-03-20 19:21:19 +01:00
|
|
|
|
2003-08-13 01:50:54 +02:00
|
|
|
static CRITICAL_SECTION X11DRV_CritSection;
|
|
|
|
static CRITICAL_SECTION_DEBUG critsect_debug =
|
|
|
|
{
|
|
|
|
0, 0, &X11DRV_CritSection,
|
|
|
|
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
|
|
|
|
0, 0, { 0, (DWORD)(__FILE__ ": X11DRV_CritSection") }
|
|
|
|
};
|
|
|
|
static CRITICAL_SECTION X11DRV_CritSection = { &critsect_debug, -1, 0, 0, 0, 0 };
|
2001-01-17 21:22:22 +01:00
|
|
|
|
2000-03-25 15:05:06 +01:00
|
|
|
Screen *screen;
|
|
|
|
Visual *visual;
|
2000-08-01 01:32:47 +02:00
|
|
|
unsigned int screen_width;
|
|
|
|
unsigned int screen_height;
|
|
|
|
unsigned int screen_depth;
|
2000-03-25 15:05:06 +01:00
|
|
|
Window root_window;
|
2003-01-28 01:34:07 +01:00
|
|
|
DWORD desktop_tid = 0;
|
2004-06-14 18:58:38 +02:00
|
|
|
int dxgrab = 0;
|
|
|
|
int usedga = 0;
|
|
|
|
int usexvidmode = 0;
|
|
|
|
int usexrandr = 1;
|
2003-03-23 21:07:55 +01:00
|
|
|
int use_xkb = 1;
|
2002-09-19 01:09:50 +02:00
|
|
|
int use_take_focus = 1;
|
2005-04-21 19:31:50 +02:00
|
|
|
int use_primary_selection = 0;
|
2002-05-23 18:32:32 +02:00
|
|
|
int managed_mode = 1;
|
2005-06-14 20:12:15 +02:00
|
|
|
int private_color_map = 0;
|
2002-11-14 23:31:34 +01:00
|
|
|
int client_side_with_core = 1;
|
|
|
|
int client_side_with_render = 1;
|
|
|
|
int client_side_antialias_with_core = 1;
|
|
|
|
int client_side_antialias_with_render = 1;
|
2004-02-13 04:58:21 +01:00
|
|
|
int using_wine_desktop = 0;
|
2005-06-14 20:12:15 +02:00
|
|
|
int copy_default_colors = 128;
|
|
|
|
int alloc_system_colors = 256;
|
2005-06-01 13:08:39 +02:00
|
|
|
DWORD thread_data_tls_index = TLS_OUT_OF_INDEXES;
|
2000-03-20 19:21:19 +01:00
|
|
|
|
2001-03-24 00:45:45 +01:00
|
|
|
static BOOL synchronous; /* run in synchronous mode? */
|
2004-08-09 20:48:49 +02:00
|
|
|
static BOOL desktop_dbl_buf = TRUE;
|
2001-03-24 00:45:45 +01:00
|
|
|
static char *desktop_geometry;
|
2001-05-16 21:52:29 +02:00
|
|
|
static XVisualInfo *desktop_vi;
|
2001-03-24 00:45:45 +01:00
|
|
|
|
2002-04-24 23:32:11 +02:00
|
|
|
static x11drv_error_callback err_callback; /* current callback for error */
|
|
|
|
static Display *err_callback_display; /* display callback is set for */
|
|
|
|
static void *err_callback_arg; /* error callback argument */
|
|
|
|
static int err_callback_result; /* error callback result */
|
2003-11-09 01:34:43 +01:00
|
|
|
static unsigned long err_serial; /* serial number of first request */
|
2002-04-24 23:32:11 +02:00
|
|
|
static int (*old_error_handler)( Display *, XErrorEvent * );
|
2004-01-21 03:22:26 +01:00
|
|
|
static int use_xim = 1;
|
|
|
|
static char input_style[20];
|
2002-04-24 23:32:11 +02:00
|
|
|
|
2001-07-23 02:04:00 +02:00
|
|
|
#define IS_OPTION_TRUE(ch) \
|
|
|
|
((ch) == 'y' || (ch) == 'Y' || (ch) == 't' || (ch) == 'T' || (ch) == '1')
|
|
|
|
#define IS_OPTION_FALSE(ch) \
|
|
|
|
((ch) == 'n' || (ch) == 'N' || (ch) == 'f' || (ch) == 'F' || (ch) == '0')
|
|
|
|
|
2003-11-21 06:30:34 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ignore_error
|
|
|
|
*
|
|
|
|
* Check if the X error is one we can ignore.
|
|
|
|
*/
|
|
|
|
static inline BOOL ignore_error( Display *display, XErrorEvent *event )
|
|
|
|
{
|
|
|
|
if (event->request_code == X_SetInputFocus && event->error_code == BadMatch) return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-17 21:22:22 +01:00
|
|
|
/***********************************************************************
|
2002-04-24 23:32:11 +02:00
|
|
|
* X11DRV_expect_error
|
2001-01-17 21:22:22 +01:00
|
|
|
*
|
2002-04-24 23:32:11 +02:00
|
|
|
* Setup a callback function that will be called on an X error. The
|
|
|
|
* callback must return non-zero if the error is the one it expected.
|
|
|
|
* This function acquires the x11 lock; X11DRV_check_error must be
|
|
|
|
* called in all cases to release it.
|
2001-01-17 21:22:22 +01:00
|
|
|
*/
|
2002-04-24 23:32:11 +02:00
|
|
|
void X11DRV_expect_error( Display *display, x11drv_error_callback callback, void *arg )
|
2001-01-17 21:22:22 +01:00
|
|
|
{
|
2002-04-24 23:32:11 +02:00
|
|
|
wine_tsx11_lock();
|
|
|
|
err_callback = callback;
|
|
|
|
err_callback_display = display;
|
|
|
|
err_callback_arg = arg;
|
|
|
|
err_callback_result = 0;
|
2003-11-09 01:34:43 +01:00
|
|
|
err_serial = NextRequest(display);
|
2001-01-17 21:22:22 +01:00
|
|
|
}
|
|
|
|
|
2002-04-24 23:32:11 +02:00
|
|
|
|
2001-01-17 21:22:22 +01:00
|
|
|
/***********************************************************************
|
2002-04-24 23:32:11 +02:00
|
|
|
* X11DRV_check_error
|
2001-01-17 21:22:22 +01:00
|
|
|
*
|
2002-04-24 23:32:11 +02:00
|
|
|
* Check if an expected X11 error occurred; return non-zero if yes.
|
|
|
|
* Also release the x11 lock obtained in X11DRV_expect_error.
|
2003-11-09 01:34:43 +01:00
|
|
|
* The caller is responsible for calling XSync first if necessary.
|
2001-01-17 21:22:22 +01:00
|
|
|
*/
|
2002-04-24 23:32:11 +02:00
|
|
|
int X11DRV_check_error(void)
|
2001-01-17 21:22:22 +01:00
|
|
|
{
|
2002-04-24 23:32:11 +02:00
|
|
|
int ret;
|
|
|
|
err_callback = NULL;
|
|
|
|
ret = err_callback_result;
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
return ret;
|
2001-01-17 21:22:22 +01:00
|
|
|
}
|
2002-04-24 23:32:11 +02:00
|
|
|
|
2001-01-17 21:22:22 +01:00
|
|
|
|
2000-03-20 19:21:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* error_handler
|
|
|
|
*/
|
2002-04-24 23:32:11 +02:00
|
|
|
static int error_handler( Display *display, XErrorEvent *error_evt )
|
2000-03-20 19:21:19 +01:00
|
|
|
{
|
2003-11-09 01:34:43 +01:00
|
|
|
if (err_callback && display == err_callback_display &&
|
|
|
|
(long)(error_evt->serial - err_serial) >= 0)
|
2002-04-24 23:32:11 +02:00
|
|
|
{
|
|
|
|
if ((err_callback_result = err_callback( display, error_evt, err_callback_arg )))
|
|
|
|
{
|
2003-11-21 06:30:34 +01:00
|
|
|
TRACE( "got expected error %d req %d\n",
|
|
|
|
error_evt->error_code, error_evt->request_code );
|
2002-04-24 23:32:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2003-11-21 06:30:34 +01:00
|
|
|
if (ignore_error( display, error_evt ))
|
|
|
|
{
|
|
|
|
TRACE( "got ignored error %d req %d\n",
|
|
|
|
error_evt->error_code, error_evt->request_code );
|
|
|
|
return 0;
|
|
|
|
}
|
2004-07-09 21:25:59 +02:00
|
|
|
if (synchronous)
|
|
|
|
{
|
|
|
|
ERR( "X protocol error: serial=%ld, request_code=%d - breaking into debugger\n",
|
|
|
|
error_evt->serial, error_evt->request_code );
|
|
|
|
DebugBreak(); /* force an entry in the debugger */
|
|
|
|
}
|
2002-04-24 23:32:11 +02:00
|
|
|
old_error_handler( display, error_evt );
|
2000-03-20 19:21:19 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-12-06 01:04:10 +01:00
|
|
|
/***********************************************************************
|
2002-09-25 05:29:55 +02:00
|
|
|
* wine_tsx11_lock (X11DRV.@)
|
2000-12-06 01:04:10 +01:00
|
|
|
*/
|
2002-09-25 05:29:55 +02:00
|
|
|
void wine_tsx11_lock(void)
|
2000-12-06 01:04:10 +01:00
|
|
|
{
|
2002-05-17 05:31:08 +02:00
|
|
|
EnterCriticalSection( &X11DRV_CritSection );
|
2000-12-06 01:04:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2002-09-25 05:29:55 +02:00
|
|
|
* wine_tsx11_unlock (X11DRV.@)
|
2000-12-06 01:04:10 +01:00
|
|
|
*/
|
2002-09-25 05:29:55 +02:00
|
|
|
void wine_tsx11_unlock(void)
|
2000-12-06 01:04:10 +01:00
|
|
|
{
|
2002-05-17 05:31:08 +02:00
|
|
|
LeaveCriticalSection( &X11DRV_CritSection );
|
2000-12-06 01:04:10 +01:00
|
|
|
}
|
2000-03-20 19:21:19 +01:00
|
|
|
|
2000-09-23 00:37:56 +02:00
|
|
|
|
2001-03-28 21:43:38 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* get_config_key
|
|
|
|
*
|
|
|
|
* Get a config key from either the app-specific or the default config
|
|
|
|
*/
|
|
|
|
inline static DWORD get_config_key( HKEY defkey, HKEY appkey, const char *name,
|
|
|
|
char *buffer, DWORD size )
|
|
|
|
{
|
|
|
|
if (appkey && !RegQueryValueExA( appkey, name, 0, NULL, buffer, &size )) return 0;
|
2005-06-16 18:14:46 +02:00
|
|
|
if (defkey && !RegQueryValueExA( defkey, name, 0, NULL, buffer, &size )) return 0;
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
2001-03-28 21:43:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-05-15 04:46:44 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* setup_options
|
|
|
|
*
|
|
|
|
* Setup the x11drv options.
|
|
|
|
*/
|
|
|
|
static void setup_options(void)
|
|
|
|
{
|
2001-03-28 21:43:38 +02:00
|
|
|
char buffer[MAX_PATH+16];
|
|
|
|
HKEY hkey, appkey = 0;
|
2004-05-19 05:22:55 +02:00
|
|
|
DWORD len;
|
2000-05-15 04:46:44 +02:00
|
|
|
|
2005-06-16 18:14:46 +02:00
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\X11 Driver */
|
|
|
|
if (RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\X11 Driver", &hkey )) hkey = 0;
|
2000-05-15 04:46:44 +02:00
|
|
|
|
2001-03-28 21:43:38 +02:00
|
|
|
/* open the app-specific key */
|
|
|
|
|
2004-05-19 05:22:55 +02:00
|
|
|
len = (GetModuleFileNameA( 0, buffer, MAX_PATH ));
|
|
|
|
if (len && len < MAX_PATH)
|
2001-03-28 21:43:38 +02:00
|
|
|
{
|
|
|
|
HKEY tmpkey;
|
|
|
|
char *p, *appname = buffer;
|
|
|
|
if ((p = strrchr( appname, '/' ))) appname = p + 1;
|
|
|
|
if ((p = strrchr( appname, '\\' ))) appname = p + 1;
|
2005-06-16 18:14:46 +02:00
|
|
|
strcat( appname, "\\X11 Driver" );
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\AppDefaults\app.exe\X11 Driver */
|
|
|
|
if (!RegOpenKeyA( HKEY_CURRENT_USER, "Software\\Wine\\AppDefaults", &tmpkey ))
|
2001-03-28 21:43:38 +02:00
|
|
|
{
|
|
|
|
if (RegOpenKeyA( tmpkey, appname, &appkey )) appkey = 0;
|
|
|
|
RegCloseKey( tmpkey );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!get_config_key( hkey, appkey, "Desktop", buffer, sizeof(buffer) ))
|
2001-03-24 00:45:45 +01:00
|
|
|
{
|
|
|
|
/* Imperfect validation: If Desktop=N, then we don't turn on
|
|
|
|
** the --desktop option. We should really validate for a correct
|
|
|
|
** sizing entry */
|
|
|
|
if (!IS_OPTION_FALSE(buffer[0])) desktop_geometry = strdup(buffer);
|
|
|
|
}
|
|
|
|
|
2002-05-23 18:32:32 +02:00
|
|
|
if (!get_config_key( hkey, appkey, "Managed", buffer, sizeof(buffer) ))
|
|
|
|
managed_mode = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
2001-04-27 20:00:06 +02:00
|
|
|
if (!get_config_key( hkey, appkey, "DXGrab", buffer, sizeof(buffer) ))
|
|
|
|
dxgrab = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
|
|
|
if (!get_config_key( hkey, appkey, "UseDGA", buffer, sizeof(buffer) ))
|
|
|
|
usedga = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
2001-09-11 01:05:57 +02:00
|
|
|
if (!get_config_key( hkey, appkey, "UseXVidMode", buffer, sizeof(buffer) ))
|
|
|
|
usexvidmode = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
2003-10-16 02:21:42 +02:00
|
|
|
if (!get_config_key( hkey, appkey, "UseXRandR", buffer, sizeof(buffer) ))
|
|
|
|
usexrandr = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
2002-09-19 01:09:50 +02:00
|
|
|
if (!get_config_key( hkey, appkey, "UseTakeFocus", buffer, sizeof(buffer) ))
|
|
|
|
use_take_focus = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
2005-04-21 19:31:50 +02:00
|
|
|
if (!get_config_key( hkey, appkey, "UsePrimarySelection", buffer, sizeof(buffer) ))
|
|
|
|
use_primary_selection = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
2001-03-24 00:45:45 +01:00
|
|
|
screen_depth = 0;
|
2001-03-28 21:43:38 +02:00
|
|
|
if (!get_config_key( hkey, appkey, "ScreenDepth", buffer, sizeof(buffer) ))
|
2001-03-24 00:45:45 +01:00
|
|
|
screen_depth = atoi(buffer);
|
|
|
|
|
2001-03-28 21:43:38 +02:00
|
|
|
if (!get_config_key( hkey, appkey, "Synchronous", buffer, sizeof(buffer) ))
|
2001-03-24 00:45:45 +01:00
|
|
|
synchronous = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
2002-11-14 23:31:34 +01:00
|
|
|
if (!get_config_key( hkey, appkey, "ClientSideWithCore", buffer, sizeof(buffer) ))
|
|
|
|
client_side_with_core = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
|
|
|
if (!get_config_key( hkey, appkey, "ClientSideWithRender", buffer, sizeof(buffer) ))
|
|
|
|
client_side_with_render = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
|
|
|
if (!get_config_key( hkey, appkey, "ClientSideAntiAliasWithCore", buffer, sizeof(buffer) ))
|
|
|
|
client_side_antialias_with_core = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
|
|
|
if (!get_config_key( hkey, appkey, "ClientSideAntiAliasWithRender", buffer, sizeof(buffer) ))
|
|
|
|
client_side_antialias_with_render = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
2002-11-15 05:16:38 +01:00
|
|
|
if (!get_config_key( hkey, appkey, "DesktopDoubleBuffered", buffer, sizeof(buffer) ))
|
|
|
|
desktop_dbl_buf = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
2004-01-21 03:22:26 +01:00
|
|
|
if (!get_config_key( hkey, appkey, "UseXIM", buffer, sizeof(buffer) ))
|
|
|
|
use_xim = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
2005-06-14 20:12:15 +02:00
|
|
|
if (!get_config_key( hkey, appkey, "PrivateColorMap", buffer, sizeof(buffer) ))
|
|
|
|
private_color_map = IS_OPTION_TRUE( buffer[0] );
|
|
|
|
|
|
|
|
if (!get_config_key( hkey, appkey, "CopyDefaultColors", buffer, sizeof(buffer) ))
|
|
|
|
copy_default_colors = atoi(buffer);
|
|
|
|
|
|
|
|
if (!get_config_key( hkey, appkey, "AllocSystemColors", buffer, sizeof(buffer) ))
|
|
|
|
alloc_system_colors = atoi(buffer);
|
|
|
|
|
2004-01-21 03:22:26 +01:00
|
|
|
get_config_key( hkey, appkey, "InputStyle", input_style, sizeof(input_style) );
|
|
|
|
|
2001-03-28 21:43:38 +02:00
|
|
|
if (appkey) RegCloseKey( appkey );
|
2005-06-16 18:14:46 +02:00
|
|
|
if (hkey) RegCloseKey( hkey );
|
2000-05-15 04:46:44 +02:00
|
|
|
}
|
|
|
|
|
2001-03-28 21:43:38 +02:00
|
|
|
|
2000-03-20 19:21:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV process initialisation routine
|
|
|
|
*/
|
2004-07-13 05:49:52 +02:00
|
|
|
static BOOL process_attach(void)
|
2000-03-20 19:21:19 +01:00
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
Display *display;
|
|
|
|
|
2000-05-15 04:46:44 +02:00
|
|
|
setup_options();
|
|
|
|
|
2005-06-01 13:08:39 +02:00
|
|
|
if ((thread_data_tls_index = TlsAlloc()) == TLS_OUT_OF_INDEXES) return FALSE;
|
|
|
|
|
2000-03-20 19:21:19 +01:00
|
|
|
/* Open display */
|
2000-05-15 04:46:44 +02:00
|
|
|
|
2004-07-13 05:49:52 +02:00
|
|
|
if (!(display = XOpenDisplay( NULL ))) return FALSE;
|
|
|
|
|
2000-04-04 21:57:23 +02:00
|
|
|
fcntl( ConnectionNumber(display), F_SETFD, 1 ); /* set close on exec flag */
|
2000-03-25 15:05:06 +01:00
|
|
|
screen = DefaultScreenOfDisplay( display );
|
|
|
|
visual = DefaultVisual( display, DefaultScreen(display) );
|
|
|
|
root_window = DefaultRootWindow( display );
|
2002-04-24 23:32:11 +02:00
|
|
|
old_error_handler = XSetErrorHandler( error_handler );
|
2000-03-25 15:05:06 +01:00
|
|
|
|
|
|
|
/* Initialize screen depth */
|
|
|
|
|
|
|
|
if (screen_depth) /* depth specified */
|
|
|
|
{
|
|
|
|
int depth_count, i;
|
2003-11-21 01:17:33 +01:00
|
|
|
int *depth_list = XListDepths(display, DefaultScreen(display), &depth_count);
|
2000-03-25 15:05:06 +01:00
|
|
|
for (i = 0; i < depth_count; i++)
|
|
|
|
if (depth_list[i] == screen_depth) break;
|
2003-11-21 01:17:33 +01:00
|
|
|
XFree( depth_list );
|
2000-03-25 15:05:06 +01:00
|
|
|
if (i >= depth_count)
|
2004-07-13 05:49:52 +02:00
|
|
|
{
|
|
|
|
WARN( "invalid depth %d, using default\n", screen_depth );
|
|
|
|
screen_depth = 0;
|
|
|
|
}
|
2000-03-25 15:05:06 +01:00
|
|
|
}
|
2004-07-13 05:49:52 +02:00
|
|
|
if (!screen_depth) screen_depth = DefaultDepthOfScreen( screen );
|
2000-03-25 15:05:06 +01:00
|
|
|
|
2002-11-15 05:16:38 +01:00
|
|
|
/* Initialize OpenGL */
|
|
|
|
X11DRV_OpenGL_Init(display);
|
|
|
|
|
2001-03-28 03:45:08 +02:00
|
|
|
/* If OpenGL is available, change the default visual, etc as necessary */
|
2002-11-15 05:16:38 +01:00
|
|
|
if (desktop_dbl_buf && (desktop_vi = X11DRV_setup_opengl_visual( display )))
|
2002-09-25 02:29:56 +02:00
|
|
|
{
|
|
|
|
visual = desktop_vi->visual;
|
|
|
|
screen = ScreenOfDisplay(display, desktop_vi->screen);
|
|
|
|
screen_depth = desktop_vi->depth;
|
|
|
|
}
|
2001-03-28 03:45:08 +02:00
|
|
|
|
2002-04-24 23:32:11 +02:00
|
|
|
if (synchronous) XSynchronize( display, True );
|
2000-03-20 19:21:19 +01:00
|
|
|
|
2000-08-01 01:32:47 +02:00
|
|
|
screen_width = WidthOfScreen( screen );
|
|
|
|
screen_height = HeightOfScreen( screen );
|
2000-03-25 18:30:13 +01:00
|
|
|
|
2003-10-16 02:21:42 +02:00
|
|
|
X11DRV_Settings_Init();
|
|
|
|
|
2001-03-24 00:45:45 +01:00
|
|
|
if (desktop_geometry)
|
2004-02-13 04:58:21 +01:00
|
|
|
{
|
2001-05-16 21:52:29 +02:00
|
|
|
root_window = X11DRV_create_desktop( desktop_vi, desktop_geometry );
|
2004-02-13 04:58:21 +01:00
|
|
|
using_wine_desktop = 1;
|
|
|
|
}
|
2000-03-20 19:21:19 +01:00
|
|
|
|
|
|
|
/* initialize GDI */
|
2004-07-13 05:49:52 +02:00
|
|
|
X11DRV_GDI_Initialize( display );
|
2001-01-17 22:51:07 +01:00
|
|
|
|
2001-02-14 01:27:34 +01:00
|
|
|
#ifdef HAVE_LIBXXF86VM
|
|
|
|
/* initialize XVidMode */
|
|
|
|
X11DRV_XF86VM_Init();
|
|
|
|
#endif
|
2003-10-16 02:21:42 +02:00
|
|
|
#ifdef HAVE_LIBXRANDR
|
|
|
|
/* initialize XRandR */
|
|
|
|
X11DRV_XRandR_Init();
|
|
|
|
#endif
|
2001-04-16 21:54:07 +02:00
|
|
|
#ifdef HAVE_LIBXXF86DGA2
|
|
|
|
/* initialize DGA2 */
|
|
|
|
X11DRV_XF86DGA2_Init();
|
|
|
|
#endif
|
2004-07-13 05:49:52 +02:00
|
|
|
|
2005-03-09 17:45:23 +01:00
|
|
|
X11DRV_InitKeyboard();
|
|
|
|
|
2004-07-13 05:49:52 +02:00
|
|
|
return TRUE;
|
2000-03-20 19:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-16 21:52:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV thread termination routine
|
|
|
|
*/
|
|
|
|
static void thread_detach(void)
|
|
|
|
{
|
2005-06-01 13:08:39 +02:00
|
|
|
struct x11drv_thread_data *data = TlsGetValue( thread_data_tls_index );
|
2001-05-16 21:52:29 +02:00
|
|
|
|
|
|
|
if (data)
|
|
|
|
{
|
|
|
|
CloseHandle( data->display_fd );
|
|
|
|
wine_tsx11_lock();
|
|
|
|
XCloseDisplay( data->display );
|
2003-01-30 02:08:53 +01:00
|
|
|
/* if (data->xim) XCloseIM( data->xim ); */ /* crashes Xlib */
|
2001-05-16 21:52:29 +02:00
|
|
|
wine_tsx11_unlock();
|
|
|
|
HeapFree( GetProcessHeap(), 0, data );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-20 19:21:19 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV process termination routine
|
|
|
|
*/
|
|
|
|
static void process_detach(void)
|
|
|
|
{
|
2001-04-16 21:54:07 +02:00
|
|
|
#ifdef HAVE_LIBXXF86DGA2
|
|
|
|
/* cleanup DGA2 */
|
|
|
|
X11DRV_XF86DGA2_Cleanup();
|
|
|
|
#endif
|
2001-02-14 01:27:34 +01:00
|
|
|
#ifdef HAVE_LIBXXF86VM
|
|
|
|
/* cleanup XVidMode */
|
|
|
|
X11DRV_XF86VM_Cleanup();
|
|
|
|
#endif
|
2002-11-14 23:31:34 +01:00
|
|
|
if(using_client_side_fonts)
|
|
|
|
X11DRV_XRender_Finalize();
|
2001-02-14 01:27:34 +01:00
|
|
|
|
2000-03-20 19:21:19 +01:00
|
|
|
/* cleanup GDI */
|
|
|
|
X11DRV_GDI_Finalize();
|
2001-03-24 00:45:45 +01:00
|
|
|
|
2002-05-17 05:31:08 +02:00
|
|
|
DeleteCriticalSection( &X11DRV_CritSection );
|
2005-06-01 13:08:39 +02:00
|
|
|
TlsFree( thread_data_tls_index );
|
2000-03-20 19:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-16 21:52:29 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV thread initialisation routine
|
|
|
|
*/
|
|
|
|
struct x11drv_thread_data *x11drv_init_thread_data(void)
|
|
|
|
{
|
|
|
|
struct x11drv_thread_data *data;
|
|
|
|
|
|
|
|
if (!(data = HeapAlloc( GetProcessHeap(), 0, sizeof(*data) )))
|
|
|
|
{
|
|
|
|
ERR( "could not create data\n" );
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
|
|
|
wine_tsx11_lock();
|
|
|
|
if (!(data->display = XOpenDisplay(NULL)))
|
|
|
|
{
|
|
|
|
wine_tsx11_unlock();
|
|
|
|
MESSAGE( "x11drv: Can't open display: %s\n", XDisplayName(NULL) );
|
2004-01-30 23:54:39 +01:00
|
|
|
MESSAGE( "Please ensure that your X server is running and that $DISPLAY is set correctly.\n" );
|
2001-05-16 21:52:29 +02:00
|
|
|
ExitProcess(1);
|
|
|
|
}
|
2003-01-23 02:28:12 +01:00
|
|
|
|
2004-01-21 03:22:26 +01:00
|
|
|
fcntl( ConnectionNumber(data->display), F_SETFD, 1 ); /* set close on exec flag */
|
2003-01-23 02:28:12 +01:00
|
|
|
|
2003-03-23 21:07:55 +01:00
|
|
|
#ifdef HAVE_XKB
|
2003-11-21 00:46:24 +01:00
|
|
|
if (use_xkb)
|
|
|
|
{
|
|
|
|
use_xkb = XkbUseExtension( data->display, NULL, NULL );
|
|
|
|
if (use_xkb) XkbSetDetectableAutoRepeat( data->display, True, NULL );
|
|
|
|
}
|
2003-03-23 21:07:55 +01:00
|
|
|
#endif
|
|
|
|
|
2001-05-16 21:52:29 +02:00
|
|
|
if (synchronous) XSynchronize( data->display, True );
|
|
|
|
wine_tsx11_unlock();
|
2004-01-21 03:22:26 +01:00
|
|
|
|
|
|
|
if (use_xim && !(data->xim = X11DRV_SetupXIM( data->display, input_style )))
|
|
|
|
WARN("Input Method is not available\n");
|
|
|
|
|
2002-05-30 22:40:02 +02:00
|
|
|
if (wine_server_fd_to_handle( ConnectionNumber(data->display), GENERIC_READ | SYNCHRONIZE,
|
|
|
|
FALSE, &data->display_fd ))
|
|
|
|
{
|
|
|
|
MESSAGE( "x11drv: Can't allocate handle for display fd\n" );
|
|
|
|
ExitProcess(1);
|
|
|
|
}
|
2001-05-16 21:52:29 +02:00
|
|
|
data->process_event_count = 0;
|
2002-06-14 02:08:40 +02:00
|
|
|
data->cursor = None;
|
|
|
|
data->cursor_window = None;
|
2005-03-21 13:37:00 +01:00
|
|
|
data->grab_window = None;
|
2002-09-19 01:09:50 +02:00
|
|
|
data->last_focus = 0;
|
2005-03-07 20:31:46 +01:00
|
|
|
data->selection_wnd = 0;
|
2005-06-01 13:08:39 +02:00
|
|
|
TlsSetValue( thread_data_tls_index, data );
|
2003-01-28 01:34:07 +01:00
|
|
|
if (desktop_tid) AttachThreadInput( GetCurrentThreadId(), desktop_tid, TRUE );
|
2001-05-16 21:52:29 +02:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-19 13:08:09 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* X11DRV initialisation routine
|
|
|
|
*/
|
2002-11-05 00:53:41 +01:00
|
|
|
BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
|
2000-03-19 13:08:09 +01:00
|
|
|
{
|
2004-07-13 05:49:52 +02:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
2000-03-20 19:21:19 +01:00
|
|
|
switch(reason)
|
2000-03-19 13:08:09 +01:00
|
|
|
{
|
2000-03-20 19:21:19 +01:00
|
|
|
case DLL_PROCESS_ATTACH:
|
2004-07-13 05:49:52 +02:00
|
|
|
ret = process_attach();
|
2000-03-20 19:21:19 +01:00
|
|
|
break;
|
2001-05-16 21:52:29 +02:00
|
|
|
case DLL_THREAD_DETACH:
|
|
|
|
thread_detach();
|
|
|
|
break;
|
2000-03-20 19:21:19 +01:00
|
|
|
case DLL_PROCESS_DETACH:
|
2001-01-17 22:51:07 +01:00
|
|
|
process_detach();
|
2000-03-20 19:21:19 +01:00
|
|
|
break;
|
2000-03-19 13:08:09 +01:00
|
|
|
}
|
2004-07-13 05:49:52 +02:00
|
|
|
return ret;
|
2000-03-19 13:08:09 +01:00
|
|
|
}
|
2000-03-25 18:30:13 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* GetScreenSaveActive (X11DRV.@)
|
2000-03-25 18:30:13 +01:00
|
|
|
*
|
|
|
|
* Returns the active status of the screen saver
|
|
|
|
*/
|
|
|
|
BOOL X11DRV_GetScreenSaveActive(void)
|
|
|
|
{
|
|
|
|
int timeout, temp;
|
2003-11-21 01:17:33 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
XGetScreenSaver(gdi_display, &timeout, &temp, &temp, &temp);
|
|
|
|
wine_tsx11_unlock();
|
2000-04-29 16:29:41 +02:00
|
|
|
return timeout != 0;
|
2000-03-25 18:30:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-07-02 21:59:40 +02:00
|
|
|
* SetScreenSaveActive (X11DRV.@)
|
2000-03-25 18:30:13 +01:00
|
|
|
*
|
|
|
|
* Activate/Deactivate the screen saver
|
|
|
|
*/
|
|
|
|
void X11DRV_SetScreenSaveActive(BOOL bActivate)
|
|
|
|
{
|
2001-11-20 21:27:26 +01:00
|
|
|
int timeout, interval, prefer_blanking, allow_exposures;
|
|
|
|
static int last_timeout = 15 * 60;
|
|
|
|
|
2003-11-21 01:17:33 +01:00
|
|
|
wine_tsx11_lock();
|
|
|
|
XGetScreenSaver(gdi_display, &timeout, &interval, &prefer_blanking,
|
|
|
|
&allow_exposures);
|
2001-11-20 21:27:26 +01:00
|
|
|
if (timeout) last_timeout = timeout;
|
|
|
|
|
|
|
|
timeout = bActivate ? last_timeout : 0;
|
2003-11-21 01:17:33 +01:00
|
|
|
XSetScreenSaver(gdi_display, timeout, interval, prefer_blanking,
|
|
|
|
allow_exposures);
|
|
|
|
wine_tsx11_unlock();
|
2000-03-25 18:30:13 +01:00
|
|
|
}
|