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