4 * X11-specific freeglut state query methods.
6 * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
7 * Written by John F. Fay, <fayjf@sourceforge.net>
8 * Creation date: Sat Feb 4 2012
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:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
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.
28 #include <GL/freeglut.h>
29 #include "fg_internal.h"
30 #ifdef EGL_VERSION_1_0
31 #include "egl/fg_state_egl.h"
33 #include "x11/fg_state_x11_glx.h"
36 int fgPlatformGlutDeviceGet ( GLenum eWhat )
40 case GLUT_HAS_KEYBOARD:
42 * X11 has a core keyboard by definition, although it can
43 * be present as a virtual/dummy keyboard. For now, there
44 * is no reliable way to tell if a real keyboard is present.
48 /* X11 has a mouse by definition */
52 case GLUT_NUM_MOUSE_BUTTONS:
53 /* We should be able to pass NULL when the last argument is zero,
54 * but at least one X server has a bug where this causes a segfault.
56 * In XFree86/Xorg servers, a mouse wheel is seen as two buttons
57 * rather than an Axis; "fg_main.c" expects this when
58 * checking for a wheel event.
62 int nbuttons = XGetPointerMapping(fgDisplay.pDisplay.Display, &map,0);
67 fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );
71 /* And now -- the failure. */
76 int fgPlatformGlutGet ( GLenum eWhat )
82 * Those calls are somewhat similiar, as they use XGetWindowAttributes()
91 if( fgStructure.CurrentWindow == NULL )
94 if (fgStructure.CurrentWindow->Parent)
95 /* For child window, we should return relative to upper-left
96 * of parent's client area.
98 p = fgStructure.CurrentWindow->Parent->Window.Handle;
100 p = fgDisplay.pDisplay.RootWindow;
102 XTranslateCoordinates(
103 fgDisplay.pDisplay.Display,
104 fgStructure.CurrentWindow->Window.Handle,
110 case GLUT_WINDOW_X: return x;
111 case GLUT_WINDOW_Y: return y;
115 case GLUT_WINDOW_BORDER_WIDTH:
116 case GLUT_WINDOW_HEADER_HEIGHT:
118 Atom actual_type, net_extents;
120 unsigned long nitems, bytes_after;
121 unsigned char *data = NULL;
122 int result, top, left;
124 if (fgStructure.CurrentWindow == NULL || fgStructure.CurrentWindow->Parent)
125 /* can't get widths/heights if no current window
126 * and child windows don't have borders */
129 /* try to get through _NET_FRAME_EXTENTS */
130 net_extents = XInternAtom(fgDisplay.pDisplay.Display, "_NET_FRAME_EXTENTS", False);
132 result = XGetWindowProperty(
133 fgDisplay.pDisplay.Display, fgStructure.CurrentWindow->Window.Handle, net_extents,
134 0, 4, False, AnyPropertyType,
135 &actual_type, &actual_format,
136 &nitems, &bytes_after, &data);
138 if (result == Success && nitems == 4 && bytes_after == 0)
139 /* got the data we expected, here's to hoping that
140 * _NET_FRAME_EXTENTS is supported and the data
141 * contain sensible values */
143 long *extents = (long *)data;
144 left = (int) extents[0]; /* we take left as border width, consistent with old logic. bottom and right better be the same... */
145 top = (int) extents[2];
149 /* try in the previous way as fall-back */
153 XTranslateCoordinates(
154 fgDisplay.pDisplay.Display,
155 fgStructure.CurrentWindow->Window.Handle,
156 fgDisplay.pDisplay.RootWindow,
160 /* logic below needs w */
163 XTranslateCoordinates(
164 fgDisplay.pDisplay.Display,
165 fgStructure.CurrentWindow->Window.Handle,
166 w, 0, 0, &x, &y, &w);
171 if (result == Success)
176 case GLUT_WINDOW_BORDER_WIDTH: return left;
177 case GLUT_WINDOW_HEADER_HEIGHT: return top;
181 case GLUT_WINDOW_WIDTH:
182 case GLUT_WINDOW_HEIGHT:
184 XWindowAttributes winAttributes;
186 if( fgStructure.CurrentWindow == NULL )
188 XGetWindowAttributes(
189 fgDisplay.pDisplay.Display,
190 fgStructure.CurrentWindow->Window.Handle,
195 case GLUT_WINDOW_WIDTH: return winAttributes.width ;
196 case GLUT_WINDOW_HEIGHT: return winAttributes.height ;
200 /* Colormap size is handled in a bit different way than all the rest */
201 case GLUT_WINDOW_COLORMAP_SIZE:
203 #ifndef EGL_VERSION_1_0
204 fgPlatformGetConfig( GLX_RGBA ) ||
206 fgStructure.CurrentWindow == NULL)
209 * We've got a RGBA visual, so there is no colormap at all.
210 * The other possibility is that we have no current window set.
216 XVisualInfo * visualInfo;
218 #ifdef EGL_VERSION_1_0
220 XVisualInfo visualTemplate;
222 if (!eglGetConfigAttrib(fgDisplay.pDisplay.egl.Display,
223 fgStructure.CurrentWindow->Window.pContext.egl.Config,
224 EGL_NATIVE_VISUAL_ID, &vid))
225 fgError("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID) failed");
226 visualTemplate.visualid = vid;
227 visualInfo = XGetVisualInfo(fgDisplay.pDisplay.Display, VisualIDMask, &visualTemplate, &num_visuals);
230 const GLXFBConfig fbconfig =
231 fgStructure.CurrentWindow->Window.pContext.FBConfig;
234 glXGetVisualFromFBConfig( fgDisplay.pDisplay.Display, fbconfig );
237 result = visualInfo->visual->map_entries;
245 #ifdef EGL_VERSION_1_0
246 return fghPlatformGlutGetEGL(eWhat);
248 return fghPlatformGlutGetGLX(eWhat);