2 * freeglut_internal_x11.h
\r
4 * The freeglut library private include file.
\r
6 * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
\r
7 * Written by Diederick C. Niehorster, <dcnieho@gmail.com>
\r
8 * Creation date: Fri Jan 20, 2012
\r
10 * Permission is hereby granted, free of charge, to any person obtaining a
\r
11 * copy of this software and associated documentation files (the "Software"),
\r
12 * to deal in the Software without restriction, including without limitation
\r
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
\r
14 * and/or sell copies of the Software, and to permit persons to whom the
\r
15 * Software is furnished to do so, subject to the following conditions:
\r
17 * The above copyright notice and this permission notice shall be included
\r
18 * in all copies or substantial portions of the Software.
\r
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
\r
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
\r
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
28 #ifndef FREEGLUT_INTERNAL_X11_H
\r
29 #define FREEGLUT_INTERNAL_X11_H
\r
32 /* -- PLATFORM-SPECIFIC INCLUDES ------------------------------------------- */
\r
34 #include <X11/Xlib.h>
\r
35 #include <X11/Xatom.h>
\r
36 #include <X11/keysym.h>
\r
37 #include <X11/extensions/XInput.h>
\r
38 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
\r
39 # include <X11/extensions/xf86vmode.h>
\r
41 #ifdef HAVE_X11_EXTENSIONS_XRANDR_H
\r
42 # include <X11/extensions/Xrandr.h>
\r
44 /* If GLX is too old, we will fail during runtime when multisampling
\r
45 is requested, but at least freeglut compiles. */
\r
46 #ifndef GLX_SAMPLE_BUFFERS
\r
47 # define GLX_SAMPLE_BUFFERS 0x80A8
\r
50 # define GLX_SAMPLES 0x80A9
\r
55 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
\r
56 /* The structure used by display initialization in freeglut_init.c */
\r
57 typedef struct tagSFG_PlatformDisplay SFG_PlatformDisplay;
\r
58 struct tagSFG_PlatformDisplay
\r
60 Display* Display; /* The display we are being run in. */
\r
61 int Screen; /* The screen we are about to use. */
\r
62 Window RootWindow; /* The screen's root window. */
\r
63 int Connection; /* The display's connection number */
\r
64 Atom DeleteWindow; /* The window deletion atom */
\r
65 Atom State; /* The state atom */
\r
66 Atom StateFullScreen; /* The full screen atom */
\r
68 #ifdef HAVE_X11_EXTENSIONS_XRANDR_H
\r
69 int prev_xsz, prev_ysz;
\r
71 int prev_size_valid;
\r
72 #endif /* HAVE_X11_EXTENSIONS_XRANDR_H */
\r
74 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
\r
76 * XF86VidMode may be compilable even if it fails at runtime. Therefore,
\r
77 * the validity of the VidMode has to be tracked
\r
79 int DisplayModeValid; /* Flag that indicates runtime status*/
\r
80 XF86VidModeModeLine DisplayMode; /* Current screen's display settings */
\r
81 int DisplayModeClock; /* The display mode's refresh rate */
\r
82 int DisplayViewPortX; /* saved X location of the viewport */
\r
83 int DisplayViewPortY; /* saved Y location of the viewport */
\r
84 #endif /* HAVE_X11_EXTENSIONS_XF86VMODE_H */
\r
86 int DisplayPointerX; /* saved X location of the pointer */
\r
87 int DisplayPointerY; /* saved Y location of the pointer */
\r
92 * Make "freeglut" window handle and context types so that we don't need so
\r
93 * much conditionally-compiled code later in the library.
\r
95 typedef Window SFG_WindowHandleType ;
\r
96 typedef GLXContext SFG_WindowContextType ;
\r
97 typedef struct tagSFG_PlatformContext SFG_PlatformContext;
\r
98 struct tagSFG_PlatformContext
\r
100 GLXFBConfig* FBConfig; /* The window's FBConfig */
\r
104 /* Window's state description. This structure should be kept portable. */
\r
105 typedef struct tagSFG_PlatformWindowState SFG_PlatformWindowState;
\r
106 struct tagSFG_PlatformWindowState
\r
108 int OldWidth; /* Window width from before a resize */
\r
109 int OldHeight; /* " height " " " " */
\r
113 /* -- JOYSTICK-SPECIFIC STRUCTURES AND TYPES ------------------------------- */
\r
115 * Initial defines from "js.h" starting around line 33 with the existing "freeglut_joystick.c"
\r
118 # ifdef HAVE_SYS_IOCTL_H
\r
119 # include <sys/ioctl.h>
\r
121 # ifdef HAVE_FCNTL_H
\r
122 # include <fcntl.h>
\r
124 # ifdef HAVE_ERRNO_H
\r
125 # include <errno.h>
\r
126 # include <string.h>
\r
128 # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
\r
129 /* XXX The below hack is done until freeglut's autoconf is updated. */
\r
130 # define HAVE_USB_JS 1
\r
132 # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
\r
133 # include <sys/joystick.h>
\r
136 * XXX NetBSD/amd64 systems may find that they have to steal the
\r
137 * XXX /usr/include/machine/joystick.h from a NetBSD/i386 system.
\r
138 * XXX I cannot comment whether that works for the interface, but
\r
139 * XXX it lets you compile...(^& I do not think that we can do away
\r
140 * XXX with this header.
\r
142 # include <machine/joystick.h> /* For analog joysticks */
\r
144 # define JS_DATA_TYPE joystick
\r
145 # define JS_RETURN (sizeof(struct JS_DATA_TYPE))
\r
148 # if defined(__linux__)
\r
149 # include <linux/joystick.h>
\r
151 /* check the joystick driver version */
\r
152 # if defined(JS_VERSION) && JS_VERSION >= 0x010000
\r
155 # else /* Not BSD or Linux */
\r
159 * We'll put these values in and that should
\r
160 * allow the code to at least compile when there is
\r
161 * no support. The JS open routine should error out
\r
162 * and shut off all the code downstream anyway and if
\r
163 * the application doesn't use a joystick we'll be fine.
\r
166 struct JS_DATA_TYPE
\r
173 # define JS_RETURN (sizeof(struct JS_DATA_TYPE))
\r
177 /* XXX It might be better to poll the operating system for the numbers of buttons and
\r
178 * XXX axes and then dynamically allocate the arrays.
\r
180 # define _JS_MAX_AXES 16
\r
181 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
\r
182 struct tagSFG_PlatformJoystick
\r
184 # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
\r
185 struct os_specific_s *os;
\r
189 struct js_event js;
\r
191 float tmp_axes [ _JS_MAX_AXES ];
\r
193 struct JS_DATA_TYPE js;
\r
196 char fname [ 128 ];
\r
201 /* Menu font and color definitions */
\r
202 #define FREEGLUT_MENU_FONT GLUT_BITMAP_HELVETICA_18
\r
204 #define FREEGLUT_MENU_PEN_FORE_COLORS {0.0f, 0.0f, 0.0f, 1.0f}
\r
205 #define FREEGLUT_MENU_PEN_BACK_COLORS {0.70f, 0.70f, 0.70f, 1.0f}
\r
206 #define FREEGLUT_MENU_PEN_HFORE_COLORS {0.0f, 0.0f, 0.0f, 1.0f}
\r
207 #define FREEGLUT_MENU_PEN_HBACK_COLORS {1.0f, 1.0f, 1.0f, 1.0f}
\r
212 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
\r
213 /* spaceball device functions, defined in freeglut_spaceball.c */
\r
214 int fgIsSpaceballXEvent( const XEvent *ev );
\r
215 void fgSpaceballHandleXEvent( const XEvent *ev );
\r
218 * Check if "hint" is present in "property" for "window". See freeglut_init.c
\r
220 int fgHintPresent(Window window, Atom property, Atom hint);
\r
222 /* Handler for X extension Events */
\r
223 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
\r
224 void fgHandleExtensionEvents( XEvent * ev );
\r
225 void fgRegisterDevices( Display* dpy, Window* win );
\r
229 #endif /* FREEGLUT_INTERNAL_X11_H */
\r