e2ba2038d643a33c54311a564f4b6cdbe48b9d2a
[freeglut] / src / x11 / fg_internal_x11.h
1 /*
2  * fg_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 #ifdef EGL_VERSION_1_0
34 #include "egl/fg_internal_egl.h"
35 #else
36 #include <GL/glx.h>
37 #include "x11/fg_internal_x11_glx.h"
38 #endif
39 #include <X11/Xlib.h>
40 #include <X11/Xatom.h>
41 #include <X11/keysym.h>
42 #include <X11/extensions/XInput.h>
43 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
44 #    include <X11/extensions/xf86vmode.h>
45 #endif
46 #ifdef HAVE_X11_EXTENSIONS_XRANDR_H
47 #    include <X11/extensions/Xrandr.h>
48 #endif
49
50
51 /* -- GLOBAL TYPE DEFINITIONS ---------------------------------------------- */
52 /* The structure used by display initialization in fg_init.c */
53 typedef struct tagSFG_PlatformDisplay SFG_PlatformDisplay;
54 struct tagSFG_PlatformDisplay
55 {
56     Display*        Display;            /* The display we are being run in.  */
57     int             Screen;             /* The screen we are about to use.   */
58     Window          RootWindow;         /* The screen's root window.         */
59     int             Connection;         /* The display's connection number   */
60     Atom            DeleteWindow;       /* The window deletion atom          */
61     Atom            State;              /* The state atom                    */
62     Atom            StateFullScreen;    /* The full screen atom              */
63     int             NetWMSupported;     /* Flag for EWMH Window Managers     */
64     Atom            NetWMPid;           /* The _NET_WM_PID atom              */
65     Atom            ClientMachine;      /* The client machine name atom      */
66
67 #ifdef HAVE_X11_EXTENSIONS_XRANDR_H
68     int prev_xsz, prev_ysz;
69     int prev_refresh;
70     int prev_size_valid;
71 #endif  /* HAVE_X11_EXTENSIONS_XRANDR_H */
72
73 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
74     /*
75      * XF86VidMode may be compilable even if it fails at runtime.  Therefore,
76      * the validity of the VidMode has to be tracked
77      */
78     int             DisplayModeValid;   /* Flag that indicates runtime status*/
79     XF86VidModeModeLine DisplayMode;    /* Current screen's display settings */
80     int             DisplayModeClock;   /* The display mode's refresh rate   */
81     int             DisplayViewPortX;   /* saved X location of the viewport  */
82     int             DisplayViewPortY;   /* saved Y location of the viewport  */
83 #endif /* HAVE_X11_EXTENSIONS_XF86VMODE_H */
84
85 #ifdef EGL_VERSION_1_0
86     struct tagSFG_PlatformDisplayEGL egl;
87 #endif
88
89     int             DisplayPointerX;    /* saved X location of the pointer   */
90     int             DisplayPointerY;    /* saved Y location of the pointer   */
91 };
92
93
94 /*
95  * Make "freeglut" window handle and context types so that we don't need so
96  * much conditionally-compiled code later in the library.
97  */
98 #ifndef EGL_VERSION_1_0
99 typedef Window     SFG_WindowHandleType ;
100 typedef GLXContext SFG_WindowContextType ;
101 #endif
102 typedef struct tagSFG_PlatformContext SFG_PlatformContext;
103 struct tagSFG_PlatformContext
104 {
105 #ifdef EGL_VERSION_1_0
106     struct tagSFG_PlatformContextEGL egl;
107 #else
108     GLXFBConfig    FBConfig;        /* The window's FBConfig               */
109 #endif
110 };
111
112
113 /* Window's state description. This structure should be kept portable. */
114 typedef struct tagSFG_PlatformWindowState SFG_PlatformWindowState;
115 struct tagSFG_PlatformWindowState
116 {
117     int             OldWidth;           /* Window width from before a resize */
118     int             OldHeight;          /*   "    height  "    "    "   "    */
119     GLboolean       KeyRepeating;       /* Currently in repeat mode?         */    
120 };
121
122
123 /* -- JOYSTICK-SPECIFIC STRUCTURES AND TYPES ------------------------------- */
124 /*
125  * Initial defines from "js.h" starting around line 33 with the existing "fg_joystick.c"
126  * interspersed
127  */
128 #    ifdef HAVE_SYS_IOCTL_H
129 #        include <sys/ioctl.h>
130 #    endif
131 #    ifdef HAVE_FCNTL_H
132 #        include <fcntl.h>
133 #    endif
134
135 #include <errno.h>
136 #include <string.h>
137
138 #    if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
139 /* XXX The below hack is done until freeglut's autoconf is updated. */
140 #        define HAVE_USB_JS    1
141 #        include <sys/joystick.h>
142 #        define JS_DATA_TYPE joystick
143 #        define JS_RETURN (sizeof(struct JS_DATA_TYPE))
144 #    endif
145
146 #    if defined(__linux__)
147 #        include <linux/joystick.h>
148
149 /* check the joystick driver version */
150 #        if defined(JS_VERSION) && JS_VERSION >= 0x010000
151 #            define JS_NEW
152 #        endif
153 #    else  /* Not BSD or Linux */
154 #        ifndef JS_RETURN
155
156   /*
157    * We'll put these values in and that should
158    * allow the code to at least compile when there is
159    * no support. The JS open routine should error out
160    * and shut off all the code downstream anyway and if
161    * the application doesn't use a joystick we'll be fine.
162    */
163
164   struct JS_DATA_TYPE
165   {
166     int buttons;
167     int x;
168     int y;
169   };
170
171 #            define JS_RETURN (sizeof(struct JS_DATA_TYPE))
172 #        endif
173 #    endif
174
175 /* XXX It might be better to poll the operating system for the numbers of buttons and
176  * XXX axes and then dynamically allocate the arrays.
177  */
178 #    define _JS_MAX_AXES 16
179 typedef struct tagSFG_PlatformJoystick SFG_PlatformJoystick;
180 struct tagSFG_PlatformJoystick
181 {
182 #   if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
183        struct os_specific_s *os;
184 #   endif
185
186 #   ifdef JS_NEW
187        struct js_event     js;
188        int          tmp_buttons;
189        float        tmp_axes [ _JS_MAX_AXES ];
190 #   else
191        struct JS_DATA_TYPE js;
192 #   endif
193
194     char         fname [ 128 ];
195     int          fd;
196 };
197
198
199 /* Menu font and color definitions */
200 #define  FREEGLUT_MENU_FONT    GLUT_BITMAP_HELVETICA_18
201
202 #define  FREEGLUT_MENU_PEN_FORE_COLORS   {0.0f,  0.0f,  0.0f,  1.0f}
203 #define  FREEGLUT_MENU_PEN_BACK_COLORS   {0.70f, 0.70f, 0.70f, 1.0f}
204 #define  FREEGLUT_MENU_PEN_HFORE_COLORS  {0.0f,  0.0f,  0.0f,  1.0f}
205 #define  FREEGLUT_MENU_PEN_HBACK_COLORS  {1.0f,  1.0f,  1.0f,  1.0f}
206
207
208
209
210 /* -- PRIVATE FUNCTION DECLARATIONS ---------------------------------------- */
211 /* spaceball device functions, defined in fg_spaceball.c */
212 int             fgIsSpaceballXEvent( const XEvent *ev );
213 void            fgSpaceballHandleXEvent( const XEvent *ev );
214
215 /*
216  * Check if "hint" is present in "property" for "window".  See fg_init.c
217  */
218 int             fgHintPresent(Window window, Atom property, Atom hint);
219
220 /* Handler for X extension Events */
221 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
222   void          fgHandleExtensionEvents( XEvent * ev );
223   void          fgRegisterDevices( Display* dpy, Window* win );
224 #endif
225
226
227 #endif  /* FREEGLUT_INTERNAL_X11_H */