Removing an extraneous "#if TARGET_HOST"
[freeglut] / src / x11 / freeglut_internal_x11.h
1 /*\r
2  * freeglut_internal_x11.h\r
3  *\r
4  * The freeglut library private include file.\r
5  *\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
9  *\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
16  *\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
19  *\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
26  */\r
27 \r
28 #ifndef  FREEGLUT_INTERNAL_X11_H\r
29 #define  FREEGLUT_INTERNAL_X11_H\r
30 \r
31 \r
32 /* -- PLATFORM-SPECIFIC INCLUDES ------------------------------------------- */\r
33 #include <GL/glx.h>\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
40 #endif\r
41 #ifdef HAVE_X11_EXTENSIONS_XRANDR_H\r
42 #    include <X11/extensions/Xrandr.h>\r
43 #endif\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
48 #endif\r
49 #ifndef GLX_SAMPLES\r
50 #    define GLX_SAMPLES 0x80A9\r
51 #endif\r
52 \r
53 \r
54 \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
59 {\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
67 \r
68 #ifdef HAVE_X11_EXTENSIONS_XRANDR_H\r
69     int prev_xsz, prev_ysz;\r
70     int prev_refresh;\r
71     int prev_size_valid;\r
72 #endif  /* HAVE_X11_EXTENSIONS_XRANDR_H */\r
73 \r
74 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H\r
75     /*\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
78      */\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
85 \r
86     int             DisplayPointerX;    /* saved X location of the pointer   */\r
87     int             DisplayPointerY;    /* saved Y location of the pointer   */\r
88 };\r
89 \r
90 \r
91 /*\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
94  */\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
99 {\r
100     GLXFBConfig*    FBConfig;        /* The window's FBConfig               */\r
101 };\r
102 \r
103 \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
107 {\r
108     int             OldWidth;           /* Window width from before a resize */\r
109     int             OldHeight;          /*   "    height  "    "    "   "    */\r
110 };\r
111 \r
112 \r
113 /* -- JOYSTICK-SPECIFIC STRUCTURES AND TYPES ------------------------------- */\r
114 /*\r
115  * Initial defines from "js.h" starting around line 33 with the existing "freeglut_joystick.c"\r
116  * interspersed\r
117  */\r
118 #    ifdef HAVE_SYS_IOCTL_H\r
119 #        include <sys/ioctl.h>\r
120 #    endif\r
121 #    ifdef HAVE_FCNTL_H\r
122 #        include <fcntl.h>\r
123 #    endif\r
124 #    ifdef HAVE_ERRNO_H\r
125 #        include <errno.h>\r
126 #        include <string.h>\r
127 #    endif\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
131 \r
132 #        if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)\r
133 #            include <sys/joystick.h>\r
134 #        else\r
135 /*\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
141  */\r
142 #            include <machine/joystick.h>         /* For analog joysticks */\r
143 #        endif\r
144 #        define JS_DATA_TYPE joystick\r
145 #        define JS_RETURN (sizeof(struct JS_DATA_TYPE))\r
146 #    endif\r
147 \r
148 #    if defined(__linux__)\r
149 #        include <linux/joystick.h>\r
150 \r
151 /* check the joystick driver version */\r
152 #        if defined(JS_VERSION) && JS_VERSION >= 0x010000\r
153 #            define JS_NEW\r
154 #        endif\r
155 #    else  /* Not BSD or Linux */\r
156 #        ifndef JS_RETURN\r
157 \r
158   /*\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
164    */\r
165 \r
166   struct JS_DATA_TYPE\r
167   {\r
168     int buttons;\r
169     int x;\r
170     int y;\r
171   };\r
172 \r
173 #            define JS_RETURN (sizeof(struct JS_DATA_TYPE))\r
174 #        endif\r
175 #    endif\r
176 \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
179  */\r
180 #    define _JS_MAX_AXES 16\r
181 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;\r
182 struct tagSFG_PlatformJoystick\r
183 {\r
184 #   if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)\r
185        struct os_specific_s *os;\r
186 #   endif\r
187 \r
188 #   ifdef JS_NEW\r
189        struct js_event     js;\r
190        int          tmp_buttons;\r
191        float        tmp_axes [ _JS_MAX_AXES ];\r
192 #   else\r
193        struct JS_DATA_TYPE js;\r
194 #   endif\r
195 \r
196     char         fname [ 128 ];\r
197     int          fd;\r
198 };\r
199 \r
200 \r
201 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */\r
202 /* spaceball device functions, defined in freeglut_spaceball.c */\r
203 int             fgIsSpaceballXEvent( const XEvent *ev );\r
204 void            fgSpaceballHandleXEvent( const XEvent *ev );\r
205 \r
206 /*\r
207  * Check if "hint" is present in "property" for "window".  See freeglut_init.c\r
208  */\r
209 int             fgHintPresent(Window window, Atom property, Atom hint);\r
210 \r
211 /* Handler for X extension Events */\r
212 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H\r
213   void          fgHandleExtensionEvents( XEvent * ev );\r
214   void          fgRegisterDevices( Display* dpy, Window* win );\r
215 #endif\r
216 \r
217 \r
218 #endif  /* FREEGLUT_INTERNAL_X11_H */\r