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
2006-05-18 14:49:52 +02:00
* Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 , 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"
2007-09-23 03:19:08 +02:00
# include "wine/port.h"
2000-05-24 01:38:32 +02:00
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
2006-04-01 14:21:31 +02:00
# ifdef HAVE_X11_EXTENSIONS_XRENDER_H
# include <X11/extensions/Xrender.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-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"
2007-09-23 03:19:08 +02:00
# include "xcomposite.h"
2002-05-30 22:40:02 +02:00
# include "wine/server.h"
# include "wine/debug.h"
2007-09-23 03:19:08 +02:00
# include "wine/library.h"
2000-03-19 13:08:09 +01:00
2002-03-10 00:29:33 +01:00
WINE_DEFAULT_DEBUG_CHANNEL ( x11drv ) ;
2006-02-24 21:05:44 +01:00
WINE_DECLARE_DEBUG_CHANNEL ( synchronous ) ;
2009-12-08 13:11:20 +01:00
WINE_DECLARE_DEBUG_CHANNEL ( winediag ) ;
2000-03-20 19:21:19 +01:00
2012-09-25 15:51:03 +02:00
XVisualInfo default_visual = { 0 } ;
2012-09-26 13:12:17 +02:00
XVisualInfo argb_visual = { 0 } ;
2012-09-26 12:53:16 +02:00
Colormap default_colormap = None ;
2011-07-06 12:38:31 +02:00
XPixmapFormatValues * * pixmap_formats ;
2007-12-16 14:00:45 +01:00
unsigned int screen_bpp ;
2000-03-25 15:05:06 +01:00
Window root_window ;
2013-11-29 12:33:09 +01:00
BOOL usexvidmode = TRUE ;
BOOL usexrandr = TRUE ;
BOOL usexcomposite = TRUE ;
BOOL use_xkb = TRUE ;
BOOL use_take_focus = TRUE ;
BOOL use_primary_selection = FALSE ;
BOOL use_system_cursors = TRUE ;
BOOL show_systray = TRUE ;
BOOL grab_pointer = TRUE ;
BOOL grab_fullscreen = FALSE ;
BOOL managed_mode = TRUE ;
BOOL decorated_mode = TRUE ;
BOOL private_color_map = FALSE ;
2006-10-23 14:37:17 +02:00
int primary_monitor = 0 ;
2013-11-29 12:33:09 +01:00
BOOL client_side_graphics = TRUE ;
BOOL client_side_with_render = TRUE ;
BOOL shape_layered_windows = TRUE ;
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 ;
2006-04-01 14:21:31 +02:00
int xrender_error_base = 0 ;
2008-05-01 10:56:34 +02:00
HMODULE x11drv_module = 0 ;
2000-03-20 19:21:19 +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 * ) ;
2013-11-29 12:33:09 +01:00
static BOOL use_xim = TRUE ;
2004-01-21 03:22:26 +01:00
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 ' )
2005-07-07 19:30:57 +02:00
Atom X11DRV_Atoms [ NB_XATOMS - FIRST_XATOM ] ;
static const char * const atom_names [ NB_XATOMS - FIRST_XATOM ] =
{
" CLIPBOARD " ,
" COMPOUND_TEXT " ,
2008-10-31 04:18:00 +01:00
" INCR " ,
2010-11-01 19:57:12 +01:00
" MANAGER " ,
2005-07-07 19:30:57 +02:00
" MULTIPLE " ,
" SELECTION_DATA " ,
" TARGETS " ,
" TEXT " ,
2016-09-28 04:38:47 +02:00
" TIMESTAMP " ,
2005-07-07 19:30:57 +02:00
" UTF8_STRING " ,
" RAW_ASCENT " ,
" RAW_DESCENT " ,
" RAW_CAP_HEIGHT " ,
2012-08-15 22:05:07 +02:00
" Rel X " ,
" Rel Y " ,
2005-07-07 19:30:57 +02:00
" WM_PROTOCOLS " ,
" WM_DELETE_WINDOW " ,
2008-02-27 19:11:43 +01:00
" WM_STATE " ,
2005-07-07 19:30:57 +02:00
" WM_TAKE_FOCUS " ,
" DndProtocol " ,
" DndSelection " ,
2008-03-05 15:57:39 +01:00
" _ICC_PROFILE " ,
2005-07-07 19:30:57 +02:00
" _MOTIF_WM_HINTS " ,
2009-01-06 19:59:07 +01:00
" _NET_STARTUP_INFO_BEGIN " ,
" _NET_STARTUP_INFO " ,
2008-03-12 17:29:28 +01:00
" _NET_SUPPORTED " ,
2006-08-23 02:14:11 +02:00
" _NET_SYSTEM_TRAY_OPCODE " ,
" _NET_SYSTEM_TRAY_S0 " ,
2012-10-01 15:59:49 +02:00
" _NET_SYSTEM_TRAY_VISUAL " ,
2010-04-16 16:23:33 +02:00
" _NET_WM_ICON " ,
2005-07-07 19:30:57 +02:00
" _NET_WM_MOVERESIZE " ,
2006-06-19 19:25:54 +02:00
" _NET_WM_NAME " ,
2005-07-07 19:30:57 +02:00
" _NET_WM_PID " ,
" _NET_WM_PING " ,
2006-06-19 19:25:54 +02:00
" _NET_WM_STATE " ,
2007-10-31 18:13:20 +01:00
" _NET_WM_STATE_ABOVE " ,
2015-10-13 07:52:37 +02:00
" _NET_WM_STATE_DEMANDS_ATTENTION " ,
2006-06-19 19:25:54 +02:00
" _NET_WM_STATE_FULLSCREEN " ,
2008-03-01 13:30:58 +01:00
" _NET_WM_STATE_MAXIMIZED_HORZ " ,
" _NET_WM_STATE_MAXIMIZED_VERT " ,
2007-10-11 11:40:55 +02:00
" _NET_WM_STATE_SKIP_PAGER " ,
" _NET_WM_STATE_SKIP_TASKBAR " ,
2010-06-29 11:08:51 +02:00
" _NET_WM_USER_TIME " ,
" _NET_WM_USER_TIME_WINDOW " ,
2008-09-12 15:54:02 +02:00
" _NET_WM_WINDOW_OPACITY " ,
2005-07-07 19:30:57 +02:00
" _NET_WM_WINDOW_TYPE " ,
2006-10-11 17:32:22 +02:00
" _NET_WM_WINDOW_TYPE_DIALOG " ,
" _NET_WM_WINDOW_TYPE_NORMAL " ,
2005-07-07 19:30:57 +02:00
" _NET_WM_WINDOW_TYPE_UTILITY " ,
2008-10-01 21:00:18 +02:00
" _NET_WORKAREA " ,
2010-11-01 19:45:12 +01:00
" _XEMBED " ,
2006-08-23 02:14:11 +02:00
" _XEMBED_INFO " ,
2005-07-07 19:30:57 +02:00
" XdndAware " ,
" XdndEnter " ,
" XdndPosition " ,
" XdndStatus " ,
" XdndLeave " ,
" XdndFinished " ,
" XdndDrop " ,
" XdndActionCopy " ,
" XdndActionMove " ,
" XdndActionLink " ,
" XdndActionAsk " ,
" XdndActionPrivate " ,
" XdndSelection " ,
" XdndTypeList " ,
2009-11-22 21:30:18 +01:00
" HTML Format " ,
2011-03-03 21:27:34 +01:00
" WCF_DIF " ,
" WCF_ENHMETAFILE " ,
" WCF_HDROP " ,
" WCF_PENDATA " ,
" WCF_RIFF " ,
" WCF_SYLK " ,
" WCF_TIFF " ,
" WCF_WAVE " ,
" image/bmp " ,
2005-07-07 19:30:57 +02:00
" image/gif " ,
2009-06-19 20:54:33 +02:00
" image/jpeg " ,
2009-06-19 20:46:57 +02:00
" image/png " ,
2005-07-07 19:30:57 +02:00
" text/html " ,
" text/plain " ,
" text/rtf " ,
2007-06-27 09:50:35 +02:00
" text/richtext " ,
" text/uri-list "
2005-07-07 19:30:57 +02:00
} ;
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 )
{
2016-12-20 17:08:28 +01:00
if ( ( event - > request_code = = X_SetInputFocus | |
event - > request_code = = X_ChangeWindowAttributes | |
event - > request_code = = X_SendEvent ) & &
( event - > error_code = = BadMatch | |
event - > error_code = = BadWindow ) ) return TRUE ;
2006-04-01 14:21:31 +02:00
2016-09-26 14:06:14 +02:00
/* the clipboard display interacts with external windows, ignore all errors */
if ( display = = clipboard_display ) return TRUE ;
2006-04-01 14:21:31 +02:00
/* ignore a number of errors on gdi display caused by creating/destroying windows */
if ( display = = gdi_display )
{
2010-04-20 20:52:17 +02:00
if ( event - > error_code = = BadDrawable | |
event - > error_code = = BadGC | |
event - > error_code = = BadWindow )
return TRUE ;
2006-04-01 14:21:31 +02:00
# ifdef HAVE_X11_EXTENSIONS_XRENDER_H
if ( xrender_error_base ) /* check for XRender errors */
{
if ( event - > error_code = = xrender_error_base + BadPicture ) return TRUE ;
}
# endif
}
2003-11-21 06:30:34 +01:00
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 .
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
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 .
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
err_callback = NULL ;
2012-08-16 16:46:37 +02:00
return err_callback_result ;
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 ;
}
2006-02-24 21:05:44 +01:00
if ( TRACE_ON ( synchronous ) )
2004-07-09 21:25:59 +02:00
{
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 ;
}
2008-02-04 14:36:18 +01:00
/***********************************************************************
2011-07-06 12:38:31 +02:00
* init_pixmap_formats
2008-02-04 14:36:18 +01:00
*/
2011-07-06 12:38:31 +02:00
static void init_pixmap_formats ( Display * display )
2008-02-04 14:36:18 +01:00
{
2011-07-06 12:38:31 +02:00
int i , count , max = 32 ;
XPixmapFormatValues * formats = XListPixmapFormats ( display , & count ) ;
for ( i = 0 ; i < count ; i + + )
2008-02-04 14:36:18 +01:00
{
2011-07-06 12:38:31 +02:00
TRACE ( " depth %u, bpp %u, pad %u \n " ,
formats [ i ] . depth , formats [ i ] . bits_per_pixel , formats [ i ] . scanline_pad ) ;
if ( formats [ i ] . depth > max ) max = formats [ i ] . depth ;
2008-02-04 14:36:18 +01:00
}
2011-07-06 12:38:31 +02:00
pixmap_formats = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , sizeof ( * pixmap_formats ) * ( max + 1 ) ) ;
for ( i = 0 ; i < count ; i + + ) pixmap_formats [ formats [ i ] . depth ] = & formats [ i ] ;
2008-02-04 14:36:18 +01: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
*/
2007-03-17 11:47:28 +01:00
static inline DWORD get_config_key ( HKEY defkey , HKEY appkey , const char * name ,
2001-03-28 21:43:38 +02:00
char * buffer , DWORD size )
{
2005-07-06 21:08:05 +02:00
if ( appkey & & ! RegQueryValueExA ( appkey , name , 0 , NULL , ( LPBYTE ) buffer , & size ) ) return 0 ;
if ( defkey & & ! RegQueryValueExA ( defkey , name , 0 , NULL , ( LPBYTE ) buffer , & size ) ) return 0 ;
2005-06-16 18:14:46 +02:00
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 ) ;
}
}
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 ] ) ;
2008-04-10 21:53:45 +02:00
if ( ! get_config_key ( hkey , appkey , " Decorated " , buffer , sizeof ( buffer ) ) )
decorated_mode = IS_OPTION_TRUE ( buffer [ 0 ] ) ;
2002-05-23 18:32:32 +02:00
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 ] ) ;
2010-10-18 12:16:28 +02:00
if ( ! get_config_key ( hkey , appkey , " UseSystemCursors " , buffer , sizeof ( buffer ) ) )
use_system_cursors = IS_OPTION_TRUE ( buffer [ 0 ] ) ;
2010-11-01 19:19:58 +01:00
if ( ! get_config_key ( hkey , appkey , " ShowSystray " , buffer , sizeof ( buffer ) ) )
show_systray = IS_OPTION_TRUE ( buffer [ 0 ] ) ;
2011-04-05 11:00:09 +02:00
if ( ! get_config_key ( hkey , appkey , " GrabPointer " , buffer , sizeof ( buffer ) ) )
grab_pointer = IS_OPTION_TRUE ( buffer [ 0 ] ) ;
2005-04-21 19:31:50 +02:00
2011-05-11 13:07:34 +02:00
if ( ! get_config_key ( hkey , appkey , " GrabFullscreen " , buffer , sizeof ( buffer ) ) )
grab_fullscreen = IS_OPTION_TRUE ( buffer [ 0 ] ) ;
2001-03-28 21:43:38 +02:00
if ( ! get_config_key ( hkey , appkey , " ScreenDepth " , buffer , sizeof ( buffer ) ) )
2012-09-25 15:51:03 +02:00
default_visual . depth = atoi ( buffer ) ;
2001-03-24 00:45:45 +01:00
2012-09-06 12:39:34 +02:00
if ( ! get_config_key ( hkey , appkey , " ClientSideGraphics " , buffer , sizeof ( buffer ) ) )
client_side_graphics = IS_OPTION_TRUE ( buffer [ 0 ] ) ;
2002-11-14 23:31:34 +01:00
if ( ! get_config_key ( hkey , appkey , " ClientSideWithRender " , buffer , sizeof ( buffer ) ) )
client_side_with_render = 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 ] ) ;
2013-01-02 18:09:34 +01:00
if ( ! get_config_key ( hkey , appkey , " ShapeLayeredWindows " , buffer , sizeof ( buffer ) ) )
shape_layered_windows = 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 ] ) ;
2006-10-23 14:37:17 +02:00
if ( ! get_config_key ( hkey , appkey , " PrimaryMonitor " , buffer , sizeof ( buffer ) ) )
primary_monitor = atoi ( buffer ) ;
2005-06-14 20:12:15 +02:00
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
}
2007-09-23 03:19:08 +02:00
# ifdef SONAME_LIBXCOMPOSITE
# define MAKE_FUNCPTR(f) typeof(f) * p##f;
MAKE_FUNCPTR ( XCompositeQueryExtension )
MAKE_FUNCPTR ( XCompositeQueryVersion )
MAKE_FUNCPTR ( XCompositeVersion )
MAKE_FUNCPTR ( XCompositeRedirectWindow )
MAKE_FUNCPTR ( XCompositeRedirectSubwindows )
MAKE_FUNCPTR ( XCompositeUnredirectWindow )
MAKE_FUNCPTR ( XCompositeUnredirectSubwindows )
MAKE_FUNCPTR ( XCompositeCreateRegionFromBorderClip )
MAKE_FUNCPTR ( XCompositeNameWindowPixmap )
# undef MAKE_FUNCPTR
static int xcomp_event_base ;
static int xcomp_error_base ;
static void X11DRV_XComposite_Init ( void )
{
void * xcomposite_handle = wine_dlopen ( SONAME_LIBXCOMPOSITE , RTLD_NOW , NULL , 0 ) ;
if ( ! xcomposite_handle )
{
TRACE ( " Unable to open %s, XComposite disabled \n " , SONAME_LIBXCOMPOSITE ) ;
2013-11-29 12:33:09 +01:00
usexcomposite = FALSE ;
2007-09-23 03:19:08 +02:00
return ;
}
# define LOAD_FUNCPTR(f) \
if ( ( p # # f = wine_dlsym ( xcomposite_handle , # f , NULL , 0 ) ) = = NULL ) \
goto sym_not_found ;
LOAD_FUNCPTR ( XCompositeQueryExtension )
LOAD_FUNCPTR ( XCompositeQueryVersion )
LOAD_FUNCPTR ( XCompositeVersion )
LOAD_FUNCPTR ( XCompositeRedirectWindow )
LOAD_FUNCPTR ( XCompositeRedirectSubwindows )
LOAD_FUNCPTR ( XCompositeUnredirectWindow )
LOAD_FUNCPTR ( XCompositeUnredirectSubwindows )
LOAD_FUNCPTR ( XCompositeCreateRegionFromBorderClip )
LOAD_FUNCPTR ( XCompositeNameWindowPixmap )
# undef LOAD_FUNCPTR
if ( ! pXCompositeQueryExtension ( gdi_display , & xcomp_event_base ,
& xcomp_error_base ) ) {
TRACE ( " XComposite extension could not be queried; disabled \n " ) ;
wine_dlclose ( xcomposite_handle , NULL , 0 ) ;
xcomposite_handle = NULL ;
2013-11-29 12:33:09 +01:00
usexcomposite = FALSE ;
2007-09-23 03:19:08 +02:00
return ;
}
TRACE ( " XComposite is up and running error_base = %d \n " , xcomp_error_base ) ;
return ;
sym_not_found :
TRACE ( " Unable to load function pointers from %s, XComposite disabled \n " , SONAME_LIBXCOMPOSITE ) ;
wine_dlclose ( xcomposite_handle , NULL , 0 ) ;
xcomposite_handle = NULL ;
2013-11-29 12:33:09 +01:00
usexcomposite = FALSE ;
2007-09-23 03:19:08 +02:00
}
# endif /* defined(SONAME_LIBXCOMPOSITE) */
2012-09-25 15:51:03 +02:00
static void init_visuals ( Display * display , int screen )
{
int count ;
XVisualInfo * info ;
default_visual . screen = screen ;
if ( default_visual . depth ) /* depth specified */
{
info = XGetVisualInfo ( display , VisualScreenMask | VisualDepthMask , & default_visual , & count ) ;
if ( info )
{
default_visual = * info ;
XFree ( info ) ;
}
else WARN ( " no visual found for depth %d \n " , default_visual . depth ) ;
}
if ( ! default_visual . visual )
{
default_visual . depth = DefaultDepth ( display , screen ) ;
default_visual . visual = DefaultVisual ( display , screen ) ;
default_visual . visualid = default_visual . visual - > visualid ;
default_visual . class = default_visual . visual - > class ;
default_visual . red_mask = default_visual . visual - > red_mask ;
default_visual . green_mask = default_visual . visual - > green_mask ;
default_visual . blue_mask = default_visual . visual - > blue_mask ;
default_visual . colormap_size = default_visual . visual - > map_entries ;
default_visual . bits_per_rgb = default_visual . visual - > bits_per_rgb ;
}
2012-09-26 13:12:17 +02:00
default_colormap = XCreateColormap ( display , root_window , default_visual . visual , AllocNone ) ;
argb_visual . screen = screen ;
argb_visual . class = TrueColor ;
argb_visual . depth = 32 ;
argb_visual . red_mask = 0xff0000 ;
argb_visual . green_mask = 0x00ff00 ;
argb_visual . blue_mask = 0x0000ff ;
if ( ( info = XGetVisualInfo ( display , VisualScreenMask | VisualDepthMask | VisualClassMask |
VisualRedMaskMask | VisualGreenMaskMask | VisualBlueMaskMask ,
& argb_visual , & count ) ) )
{
argb_visual = * info ;
XFree ( info ) ;
}
TRACE ( " default visual %lx class %u argb %lx \n " ,
default_visual . visualid , default_visual . class , argb_visual . visualid ) ;
2012-09-25 15:51:03 +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
{
2011-04-12 21:16:15 +02:00
char error [ 1024 ] ;
2001-05-16 21:52:29 +02:00
Display * display ;
2011-04-12 21:16:15 +02:00
void * libx11 = wine_dlopen ( SONAME_LIBX11 , RTLD_NOW | RTLD_GLOBAL , error , sizeof ( error ) ) ;
if ( ! libx11 )
{
ERR ( " failed to load %s: %s \n " , SONAME_LIBX11 , error ) ;
return FALSE ;
}
pXGetEventData = wine_dlsym ( libx11 , " XGetEventData " , NULL , 0 ) ;
pXFreeEventData = wine_dlsym ( libx11 , " XFreeEventData " , NULL , 0 ) ;
# ifdef SONAME_LIBXEXT
wine_dlopen ( SONAME_LIBXEXT , RTLD_NOW | RTLD_GLOBAL , NULL , 0 ) ;
# endif
2001-05-16 21:52:29 +02:00
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
2012-05-05 12:13:38 +02:00
if ( ! XInitThreads ( ) ) ERR ( " XInitThreads failed, trouble ahead \n " ) ;
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
root_window = DefaultRootWindow ( display ) ;
2005-06-29 21:28:06 +02:00
gdi_display = display ;
2002-04-24 23:32:11 +02:00
old_error_handler = XSetErrorHandler ( error_handler ) ;
2000-03-25 15:05:06 +01:00
2011-07-06 12:38:31 +02:00
init_pixmap_formats ( display ) ;
2012-09-25 15:51:03 +02:00
init_visuals ( display , DefaultScreen ( display ) ) ;
screen_bpp = pixmap_formats [ default_visual . depth ] - > bits_per_pixel ;
2007-12-16 14:00:45 +01:00
2005-07-07 19:30:57 +02:00
XInternAtoms ( display , ( char * * ) atom_names , NB_XATOMS - FIRST_XATOM , False , X11DRV_Atoms ) ;
2012-08-15 15:51:06 +02:00
winContext = XUniqueContext ( ) ;
win_data_context = XUniqueContext ( ) ;
cursor_context = XUniqueContext ( ) ;
2006-02-24 21:05:44 +01:00
if ( TRACE_ON ( synchronous ) ) XSynchronize ( display , True ) ;
2000-03-20 19:21:19 +01:00
2012-09-25 15:51:03 +02:00
xinerama_init ( DisplayWidth ( display , default_visual . screen ) ,
DisplayHeight ( display , default_visual . screen ) ) ;
2003-10-16 02:21:42 +02:00
X11DRV_Settings_Init ( ) ;
2001-02-14 01:27:34 +01:00
/* initialize XVidMode */
X11DRV_XF86VM_Init ( ) ;
2003-10-16 02:21:42 +02:00
/* initialize XRandR */
X11DRV_XRandR_Init ( ) ;
2007-09-23 03:19:08 +02:00
# ifdef SONAME_LIBXCOMPOSITE
X11DRV_XComposite_Init ( ) ;
# endif
2011-04-13 20:18:30 +02:00
X11DRV_XInput2_Init ( ) ;
2004-07-13 05:49:52 +02:00
2008-07-02 12:03:52 +02:00
# ifdef HAVE_XKB
if ( use_xkb ) use_xkb = XkbUseExtension ( gdi_display , NULL , NULL ) ;
# endif
2008-02-06 20:37:41 +01:00
X11DRV_InitKeyboard ( gdi_display ) ;
2008-04-10 12:29:01 +02:00
if ( use_xim ) use_xim = X11DRV_InitXIM ( input_style ) ;
2005-03-09 17:45:23 +01:00
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
/***********************************************************************
2016-08-29 19:58:20 +02:00
* ThreadDetach ( X11DRV . @ )
2001-05-16 21:52:29 +02:00
*/
2016-08-29 19:58:20 +02:00
void CDECL X11DRV_ThreadDetach ( void )
2001-05-16 21:52:29 +02:00
{
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 )
{
2006-10-24 12:39:28 +02:00
if ( data - > xim ) XCloseIM ( data - > xim ) ;
2008-10-18 16:03:48 +02:00
if ( data - > font_set ) XFreeFontSet ( data - > display , data - > font_set ) ;
2001-05-16 21:52:29 +02:00
XCloseDisplay ( data - > display ) ;
HeapFree ( GetProcessHeap ( ) , 0 , data ) ;
2013-10-16 19:45:22 +02:00
/* clear data in case we get re-entered from user32 before the thread is truly dead */
TlsSetValue ( thread_data_tls_index , NULL ) ;
2001-05-16 21:52:29 +02:00
}
}
2007-04-04 18:02:53 +02:00
/* store the display fd into the message queue */
static void set_queue_display_fd ( Display * display )
{
HANDLE handle ;
int ret ;
if ( wine_server_fd_to_handle ( ConnectionNumber ( display ) , GENERIC_READ | SYNCHRONIZE , 0 , & handle ) )
{
MESSAGE ( " x11drv: Can't allocate handle for display fd \n " ) ;
ExitProcess ( 1 ) ;
}
SERVER_START_REQ ( set_queue_fd )
{
2008-12-08 16:05:17 +01:00
req - > handle = wine_server_obj_handle ( handle ) ;
2007-04-04 18:02:53 +02:00
ret = wine_server_call ( req ) ;
}
SERVER_END_REQ ;
if ( ret )
{
MESSAGE ( " x11drv: Can't store handle for display fd \n " ) ;
ExitProcess ( 1 ) ;
}
CloseHandle ( handle ) ;
}
2001-05-16 21:52:29 +02:00
/***********************************************************************
* X11DRV thread initialisation routine
*/
struct x11drv_thread_data * x11drv_init_thread_data ( void )
{
2008-06-26 15:08:08 +02:00
struct x11drv_thread_data * data = x11drv_thread_data ( ) ;
if ( data ) return data ;
2001-05-16 21:52:29 +02:00
2008-03-13 13:35:02 +01:00
if ( ! ( data = HeapAlloc ( GetProcessHeap ( ) , HEAP_ZERO_MEMORY , sizeof ( * data ) ) ) )
2001-05-16 21:52:29 +02:00
{
ERR ( " could not create data \n " ) ;
ExitProcess ( 1 ) ;
}
if ( ! ( data - > display = XOpenDisplay ( NULL ) ) )
{
2009-12-08 13:11:20 +01:00
ERR_ ( winediag ) ( " x11drv: Can't open display: %s. Please ensure that your X server is running and that $DISPLAY is set correctly. \n " , XDisplayName ( NULL ) ) ;
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
2008-07-02 12:03:26 +02:00
if ( use_xkb & & XkbUseExtension ( data - > display , NULL , NULL ) )
XkbSetDetectableAutoRepeat ( data - > display , True , NULL ) ;
2003-03-23 21:07:55 +01:00
# endif
2006-02-24 21:05:44 +01:00
if ( TRACE_ON ( synchronous ) ) XSynchronize ( data - > display , True ) ;
2004-01-21 03:22:26 +01:00
2007-04-04 18:02:53 +02:00
set_queue_display_fd ( data - > display ) ;
2005-06-01 13:08:39 +02:00
TlsSetValue ( thread_data_tls_index , data ) ;
2008-04-10 12:29:01 +02:00
2008-04-04 13:44:36 +02:00
if ( use_xim ) X11DRV_SetupXIM ( ) ;
2008-04-10 12:29:01 +02:00
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 :
2016-08-29 19:58:20 +02:00
DisableThreadLibraryCalls ( hinst ) ;
2008-05-01 10:56:34 +02:00
x11drv_module = hinst ;
2004-07-13 05:49:52 +02:00
ret = process_attach ( ) ;
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
/***********************************************************************
2012-11-15 17:46:37 +01:00
* SystemParametersInfo ( X11DRV . @ )
2000-03-25 18:30:13 +01:00
*/
2012-11-15 17:46:37 +01:00
BOOL CDECL X11DRV_SystemParametersInfo ( UINT action , UINT int_param , void * ptr_param , UINT flags )
2000-03-25 18:30:13 +01:00
{
2012-11-15 17:46:37 +01:00
switch ( action )
{
case SPI_GETSCREENSAVEACTIVE :
if ( ptr_param )
{
int timeout , temp ;
XGetScreenSaver ( gdi_display , & timeout , & temp , & temp , & temp ) ;
* ( BOOL * ) ptr_param = timeout ! = 0 ;
return TRUE ;
}
break ;
case SPI_SETSCREENSAVEACTIVE :
{
int timeout , interval , prefer_blanking , allow_exposures ;
static int last_timeout = 15 * 60 ;
XLockDisplay ( gdi_display ) ;
XGetScreenSaver ( gdi_display , & timeout , & interval , & prefer_blanking ,
& allow_exposures ) ;
if ( timeout ) last_timeout = timeout ;
timeout = int_param ? last_timeout : 0 ;
XSetScreenSaver ( gdi_display , timeout , interval , prefer_blanking ,
allow_exposures ) ;
XUnlockDisplay ( gdi_display ) ;
}
break ;
}
return FALSE ; /* let user32 handle it */
2000-03-25 18:30:13 +01:00
}