#ifndef	ARCH_WINLIB_X11_H
#define	ARCH_WINLIB_X11_H

#ifdef	ARCH_WINDOWING_SUPPORTED

#include <locale.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>

#ifdef	ARCH_HAVE_XF86_VIDMODE
#include <X11/extensions/xf86vmode.h>
#endif	/* ARCH_HAVE_XF86_VIDMODE */

typedef struct x11_display_connection_s
{
	int ref_count;
	Window root;
	int scrnum;
	int screen_width, screen_height;
	char *lang;
	Display *dpy;
	XIM im;
	Atom wm_protocols_atom;
	Atom wm_delete_window_atom;
	Cursor null_cursor;
	vboolean grab_keyboard;
	int connection_fd;
#ifdef	ARCH_HAVE_XF86_VIDMODE
	int num_vidmodes;
	vboolean vidmode_active;
	XF86VidModeModeInfo **xf86_vidmodes;
	vidmode_p vidmodes;
#endif	/* ARCH_HAVE_XF86_VIDMODE */
}	x11_display_connection_t, *x11_display_connection_p;

/*
 * Global data: hold biglock before writing.
 * If coded properly, read access should be safe without lock.
 */
extern x11_display_connection_t x11_display_connection;

typedef struct arch_window_s
{
	ARCH_COMMON_WINDOW_FIELDS
	x11_display_connection_p cn;
	Window		parent, wnd;
	XIC			ic;
	unsigned	event_mask;
	unsigned	keycode_to_scan[256];
	Colormap	cmap;
}	arch_window_t, *arch_window_p;

#include <../arch/common/glctx.h>
#include <../include/GL/glx.h>

typedef struct gl_context_s
{
	ARCH_COMMON_GL_CONTEXT_FIELDS
	XVisualInfo *visual_info;
	GLXContext glx_context;
}	gl_context_t, *gl_context_p;

#ifdef __cplusplus
extern "C" {
#endif
	/*
	 * x11_open_connection() can only be caller by WinOpen() / vglInit()
	 * x11_close_connection() can only be caller by WinClose() / vglDestroy()
	 */
	x11_display_connection_p V_CALL x11_open_connection();
	void V_CALL x11_close_connection();
#ifdef __cplusplus
}
#endif

#endif	/* ARCH_WINDOWING_SUPPORTED */

#endif	/* !ARCH_WINLIB_X11_H */
