Index: generic/tk.h
==================================================================
--- generic/tk.h
+++ generic/tk.h
@@ -84,14 +84,11 @@
  */
 
 #ifndef RC_INVOKED
 
 #ifndef _XLIB_H
-#   include <X11/Xlib.h>
-#   ifdef MAC_OSX_TK
-#	include <X11/X.h>
-#   endif
+#   include <tkLocalXlib.h>
 #endif
 #ifdef __STDC__
 #   include <stddef.h>
 #endif
 

Index: generic/tkIntXlibDecls.h
==================================================================
--- generic/tkIntXlibDecls.h
+++ generic/tkIntXlibDecls.h
@@ -29,11 +29,11 @@
 
 /* Some (older) versions of X11/Xutil.h have a wrong signature of those
    two functions, so move them out of the way temporarly. */
 #define XOffsetRegion _XOffsetRegion
 #define XUnionRegion _XUnionRegion
-#include "X11/Xutil.h"
+#include "tkLocalXutil.h"
 #undef XOffsetRegion
 #undef XUnionRegion
 
 #ifdef BUILD_tk
 #  undef TCL_STORAGE_CLASS

Index: unix/Makefile.in
==================================================================
--- unix/Makefile.in
+++ unix/Makefile.in
@@ -146,11 +146,11 @@
 
 # A "-I" switch that can be used when compiling to make all of the
 # X11 include files accessible (the configure script will try to
 # set this value, and will cause it to be an empty string if the
 # include files are accessible via /usr/include).
-X11_INCLUDES		= @XINCLUDES@
+X11_INCLUDES		= @XINCLUDES@ -I$(XLIB_DIR)
 
 AQUA_INCLUDES		= -I$(MAC_OSX_DIR) -I$(XLIB_DIR)
 
 # Linker switch(es) to use to link with the X11 library archive (the
 # configure script will try to set this value automatically, but you
@@ -546,23 +546,27 @@
 	$(MAC_OSX_DIR)/tkAboutDlg.r $(MAC_OSX_DIR)/tkMacOSXCursors.r \
 	$(MAC_OSX_DIR)/tkMacOSXXCursors.r
 
 AQUA_WISH_RESOURCES = $(MAC_OSX_DIR)/tkMacOSXAETE.r
 
-AQUA_HDRS = $(MAC_OSX_DIR)/tkMacOSX.h $(GENERIC_DIR)/tkIntXlibDecls.h
+AQUA_HDRS = $(MAC_OSX_DIR)/tkMacOSX.h $(GENERIC_DIR)/tkIntXlibDecls.h $(XLIB_DIR)/tkLocalXutil.h
 
-AQUA_XLIB_HDRS = $(XLIB_DIR)/X11/*.h $(XLIB_DIR)/xbytes.h
+AQUA_XLIB_HDRS = $(XLIB_DIR)/X11/tkLocalXlib.h $(XLIB_DIR)/X11/tkLocalXutil.h
+
+AQUA_TK_XLIB_HDRS = $(XLIB_DIR)/X11/X.h $(XLIB_DIR)/X11/Xatom.h $(XLIB_DIR)/X11/Xfuncproto.h \
+	$(XLIB_DIR)/X11/Xlib.h $(XLIB_DIR)/X11/Xutil.h $(XLIB_DIR)/X11/cursorfont.h \
+	$(XLIB_DIR)/X11/keysym.h $(XLIB_DIR)/X11/keysymdef.h $(XLIB_DIR)/xbytes.h
 
 AQUA_PRIVATE_HDRS = $(MAC_OSX_DIR)/tkMacOSXPort.h $(MAC_OSX_DIR)/tkMacOSXInt.h
 
-X11_PRIVATE_HDRS = $(UNIX_DIR)/tkUnixPort.h $(UNIX_DIR)/tkUnixInt.h $(GENERIC_DIR)/tkIntXlibDecls.h
+X11_PRIVATE_HDRS = $(UNIX_DIR)/tkUnixPort.h $(UNIX_DIR)/tkUnixInt.h $(GENERIC_DIR)/tkIntXlibDecls.h $(XLIB_DIR)/tkLocalXutil.h
 
 # Currently private, eventually public
 TTK_HDRS = $(TTK_DIR)/ttkTheme.h $(TTK_DIR)/ttkDecls.h
 
 PUBLIC_HDRS = $(GENERIC_DIR)/tk.h $(GENERIC_DIR)/tkDecls.h \
-	$(GENERIC_DIR)/tkPlatDecls.h $(@TK_WINDOWINGSYSTEM@_HDRS)
+	$(GENERIC_DIR)/tkPlatDecls.h $(XLIB_DIR)/tkLocalXlib.h $(@TK_WINDOWINGSYSTEM@_HDRS)
 
 # The private headers we want installed for install-private-headers
 PRIVATE_HDRS = $(GENERIC_DIR)/tkInt.h $(GENERIC_DIR)/tkIntDecls.h \
 	$(GENERIC_DIR)/tkIntPlatDecls.h $(GENERIC_DIR)/tkPort.h \
 	$(TTK_HDRS) $(@TK_WINDOWINGSYSTEM@_PRIVATE_HDRS)
@@ -859,12 +863,13 @@
 	    $(SHELL) $(UNIX_DIR)/installManPage $(MAN_FLAGS) $$i "$(MANN_INSTALL_DIR)"; \
 	done
 
 install-headers:
 	@if test "$(@TK_WINDOWINGSYSTEM@_XLIB_HDRS)" != ""; then \
-	    XLIB_INCLUDE_INSTALL_DIR="$(INCLUDE_INSTALL_DIR)"/X11; fi; \
-	for i in "$(INCLUDE_INSTALL_DIR)" "$${XLIB_INCLUDE_INSTALL_DIR}"; \
+	    XLIB_INCLUDE_INSTALL_DIR="$(INCLUDE_INSTALL_DIR)"/X11; \
+	    TK_XLIB_INCLUDE_INSTALL_DIR="$(INCLUDE_INSTALL_DIR)"/tk/X11; fi; \
+	for i in "$(INCLUDE_INSTALL_DIR)" "$${XLIB_INCLUDE_INSTALL_DIR}" "$${TK_XLIB_INCLUDE_INSTALL_DIR}"; \
 	    do \
 	    if [ -n "$$i" -a ! -d "$$i" ] ; then \
 		echo "Making directory $$i"; \
 		$(INSTALL_DATA_DIR) "$$i"; \
 		else true; \
@@ -875,13 +880,16 @@
 	    do \
 	    $(INSTALL_DATA) $$i "$(INCLUDE_INSTALL_DIR)"; \
 	    done;
 	@list='$(@TK_WINDOWINGSYSTEM@_XLIB_HDRS)'; for i in $$list ; \
 	    do \
-	    $(INSTALL_DATA) $$i "$(INCLUDE_INSTALL_DIR)/X11"; \
+	    $(INSTALL_DATA) $$i "$(INCLUDE_INSTALL_DIR)"; \
 	    done;
-
+	@list='$(@TK_WINDOWINGSYSTEM@_TK_XLIB_HDRS)'; for i in $$list ; \
+	    do \
+	    $(INSTALL_DATA) $$i "$(INCLUDE_INSTALL_DIR)/tk/X11"; \
+	    done;
 # Optional target to install private headers
 install-private-headers:
 	@for i in "$(PRIVATE_INCLUDE_INSTALL_DIR)"; \
 	    do \
 	    if [ ! -d "$$i" ] ; then \

Index: xlib/X11/Xlib.h
==================================================================
--- xlib/X11/Xlib.h
+++ xlib/X11/Xlib.h
@@ -26,20 +26,20 @@
 #define _XLIB_H_
 
 #define XlibSpecificationRelease 5
 
 #if !defined(MAC_OSX_TK)
-#   include <X11/X.h>
+#   include "X.h"
 #endif
 #ifdef MAC_OSX_TK
-#   include <X11/X.h>
+#   include "X.h"
 #   define Cursor XCursor
 #   define Region XRegion
 #endif
 
 /* applications should not depend on these two headers being included! */
-#include <X11/Xfuncproto.h>
+#include "Xfuncproto.h"
 
 #ifndef X_WCHAR
 #ifdef X_NOT_STDC_ENV
 #define X_WCHAR
 #endif

Index: xlib/X11/Xutil.h
==================================================================
--- xlib/X11/Xutil.h
+++ xlib/X11/Xutil.h
@@ -25,11 +25,11 @@
 ******************************************************************/
 
 #ifndef _XUTIL_H_
 #define _XUTIL_H_
 
-/* You must include <X11/Xlib.h> before including this file */
+/* You must include "Xlib.h" before including this file */
 
 #if defined(MAC_OSX_TK)
 #   define Region XRegion
 #endif
 

Index: xlib/X11/keysym.h
==================================================================
--- xlib/X11/keysym.h
+++ xlib/X11/keysym.h
@@ -30,6 +30,6 @@
 #define XK_LATIN2
 #define XK_LATIN3
 #define XK_LATIN4
 #define XK_GREEK
 
-#include <X11/keysymdef.h>
+#include "keysymdef.h"

ADDED    xlib/X11/tkLocalXlib.h
Index: xlib/X11/tkLocalXlib.h
==================================================================
--- xlib/X11/tkLocalXlib.h
+++ xlib/X11/tkLocalXlib.h
@@ -0,0 +1,9 @@
+#ifndef _TK_LOCAL_XLIB_H
+#define _TK_LOCAL_XLIB_H
+
+#include <tk/X11/Xlib.h>
+#ifdef MAC_OSX_TK
+#include <tk/X11/X.h>
+#endif
+
+#endif /* _TK_LOCAL_XLIB_H */

ADDED    xlib/X11/tkLocalXutil.h
Index: xlib/X11/tkLocalXutil.h
==================================================================
--- xlib/X11/tkLocalXutil.h
+++ xlib/X11/tkLocalXutil.h
@@ -0,0 +1,6 @@
+#ifndef _TK_LOCAL_XUTIL_H
+#define _TK_LOCAL_XUTIL_H
+
+#include <tk/X11/Xutil.h>
+
+#endif /* _TK_LOCAL_XUTIL */

ADDED    xlib/tkLocalXlib.h
Index: xlib/tkLocalXlib.h
==================================================================
--- xlib/tkLocalXlib.h
+++ xlib/tkLocalXlib.h
@@ -0,0 +1,9 @@
+#ifndef _TK_LOCAL_XLIB_H
+#define _TK_LOCAL_XLIB_H
+
+#include <X11/Xlib.h>
+#ifdef MAC_OSX_TK
+#include <X11/X.h>
+#endif
+
+#endif /* _TK_LOCAL_XLIB_H */

ADDED    xlib/tkLocalXutil.h
Index: xlib/tkLocalXutil.h
==================================================================
--- xlib/tkLocalXutil.h
+++ xlib/tkLocalXutil.h
@@ -0,0 +1,6 @@
+#ifndef _TK_LOCAL_XUTIL_H
+#define _TK_LOCAL_XUTIL_H
+
+#include "X11/Xutil.h"
+
+#endif /* _TK_LOCAL_XUTIL */

