Adding "glutFullScreenToggle" for X11 -- still needs implementation in Windows (e...
[freeglut] / src / freeglut_state.c
1 /*
2  * freeglut_state.c
3  *
4  * Freeglut state query methods.
5  *
6  * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7  * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8  * Creation date: Thu Dec 16 1999
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 #include <GL/freeglut.h>
29 #include "freeglut_internal.h"
30
31 /*
32  * TODO BEFORE THE STABLE RELEASE:
33  *
34  *  glutGet()               -- X11 tests passed, but check if all enums
35  *                             handled (what about Win32?)
36  *  glutDeviceGet()         -- X11 tests passed, but check if all enums
37  *                             handled (what about Win32?)
38  *  glutGetModifiers()      -- OK, but could also remove the limitation
39  *  glutLayerGet()          -- what about GLUT_NORMAL_DAMAGED?
40  *
41  * The fail-on-call policy will help adding the most needed things imho.
42  */
43
44 /* -- LOCAL DEFINITIONS ---------------------------------------------------- */
45
46 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
47
48 #if TARGET_HOST_POSIX_X11
49 /*
50  * Queries the GL context about some attributes
51  */
52 static int fghGetConfig( int attribute )
53 {
54   int returnValue = 0;
55   int result;  /*  Not checked  */
56
57   if( fgStructure.CurrentWindow )
58       result = glXGetFBConfigAttrib( fgDisplay.Display,
59                                      *(fgStructure.CurrentWindow->Window.FBConfig),
60                                      attribute,
61                                      &returnValue );
62
63   return returnValue;
64 }
65 #endif
66
67 /* Check if the window is in full screen state. */
68 static int fghCheckFullScreen(void)
69 {
70 #if TARGET_HOST_POSIX_X11
71
72   int result;
73
74   result = 0;
75   if (fgDisplay.StateFullScreen != None)
76     {
77       result = fgHintPresent(fgStructure.CurrentWindow->Window.Handle,
78                              fgDisplay.State,
79                              fgDisplay.StateFullScreen);
80     }
81
82   return result;
83
84 #else
85
86   return 0;
87
88 #endif
89 }
90
91 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
92
93 /*
94  * General settings assignment method
95  */
96 void FGAPIENTRY glutSetOption( GLenum eWhat, int value )
97 {
98     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSetOption" );
99
100     /*
101      * XXX In chronological code add order.  (WHY in that order?)
102      */
103     switch( eWhat )
104     {
105     case GLUT_INIT_WINDOW_X:
106         fgState.Position.X = (GLint)value;
107         break;
108
109     case GLUT_INIT_WINDOW_Y:
110         fgState.Position.Y = (GLint)value;
111         break;
112
113     case GLUT_INIT_WINDOW_WIDTH:
114         fgState.Size.X = (GLint)value;
115         break;
116
117     case GLUT_INIT_WINDOW_HEIGHT:
118         fgState.Size.Y = (GLint)value;
119         break;
120
121     case GLUT_INIT_DISPLAY_MODE:
122         fgState.DisplayMode = (unsigned int)value;
123         break;
124
125     case GLUT_ACTION_ON_WINDOW_CLOSE:
126         fgState.ActionOnWindowClose = value;
127         break;
128
129     case GLUT_RENDERING_CONTEXT:
130         fgState.UseCurrentContext =
131             ( value == GLUT_USE_CURRENT_CONTEXT ) ? GL_TRUE : GL_FALSE;
132         break;
133
134     case GLUT_DIRECT_RENDERING:
135         fgState.DirectContext = value;
136         break;
137
138     case GLUT_WINDOW_CURSOR:
139         if( fgStructure.CurrentWindow != NULL )
140             fgStructure.CurrentWindow->State.Cursor = value;
141         break;
142
143     case GLUT_AUX:
144       fgState.AuxiliaryBufferNumber = value;
145       break;
146
147     case GLUT_MULTISAMPLE:
148       fgState.SampleNumber = value;
149       break;
150
151     default:
152         fgWarning( "glutSetOption(): missing enum handle %d", eWhat );
153         break;
154     }
155 }
156
157 #if TARGET_HOST_MS_WINDOWS
158 /* The following include file is available from SGI but is not standard:
159  *   #include <GL/wglext.h>
160  * So we copy the necessary parts out of it to support the multisampling query
161  */
162 #define WGL_SAMPLES_ARB                0x2042
163 #endif
164
165
166 /*
167  * General settings query method
168  */
169 int FGAPIENTRY glutGet( GLenum eWhat )
170 {
171 #if TARGET_HOST_MS_WINDOWS
172     int returnValue ;
173     GLboolean boolValue ;
174 #endif
175
176     int nsamples = 0;
177
178     switch (eWhat)
179     {
180     case GLUT_INIT_STATE:
181         return fgState.Initialised;
182
183     case GLUT_ELAPSED_TIME:
184         return fgElapsedTime();
185     }
186
187     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGet" );
188
189     /* XXX In chronological code add order.  (WHY in that order?) */
190     switch( eWhat )
191     {
192     /* Following values are stored in fgState and fgDisplay global structures */
193     case GLUT_SCREEN_WIDTH:         return fgDisplay.ScreenWidth   ;
194     case GLUT_SCREEN_HEIGHT:        return fgDisplay.ScreenHeight  ;
195     case GLUT_SCREEN_WIDTH_MM:      return fgDisplay.ScreenWidthMM ;
196     case GLUT_SCREEN_HEIGHT_MM:     return fgDisplay.ScreenHeightMM;
197     case GLUT_INIT_WINDOW_X:        return fgState.Position.Use ?
198                                            fgState.Position.X : -1 ;
199     case GLUT_INIT_WINDOW_Y:        return fgState.Position.Use ?
200                                            fgState.Position.Y : -1 ;
201     case GLUT_INIT_WINDOW_WIDTH:    return fgState.Size.Use ?
202                                            fgState.Size.X : -1     ;
203     case GLUT_INIT_WINDOW_HEIGHT:   return fgState.Size.Use ?
204                                            fgState.Size.Y : -1     ;
205     case GLUT_INIT_DISPLAY_MODE:    return fgState.DisplayMode     ;
206
207 #if TARGET_HOST_POSIX_X11
208     /*
209      * The window/context specific queries are handled mostly by
210      * fghGetConfig().
211      */
212     case GLUT_WINDOW_NUM_SAMPLES:
213 #ifdef GLX_VERSION_1_3
214         glGetIntegerv(GL_SAMPLES, &nsamples);
215 #endif
216         return nsamples;
217
218     /*
219      * The rest of GLX queries under X are general enough to use a macro to
220      * check them
221      */
222 #   define GLX_QUERY(a,b) case a: return fghGetConfig( b );
223
224     GLX_QUERY( GLUT_WINDOW_RGBA,                GLX_RGBA                );
225     GLX_QUERY( GLUT_WINDOW_DOUBLEBUFFER,        GLX_DOUBLEBUFFER        );
226     GLX_QUERY( GLUT_WINDOW_BUFFER_SIZE,         GLX_BUFFER_SIZE         );
227     GLX_QUERY( GLUT_WINDOW_STENCIL_SIZE,        GLX_STENCIL_SIZE        );
228     GLX_QUERY( GLUT_WINDOW_DEPTH_SIZE,          GLX_DEPTH_SIZE          );
229     GLX_QUERY( GLUT_WINDOW_RED_SIZE,            GLX_RED_SIZE            );
230     GLX_QUERY( GLUT_WINDOW_GREEN_SIZE,          GLX_GREEN_SIZE          );
231     GLX_QUERY( GLUT_WINDOW_BLUE_SIZE,           GLX_BLUE_SIZE           );
232     GLX_QUERY( GLUT_WINDOW_ALPHA_SIZE,          GLX_ALPHA_SIZE          );
233     GLX_QUERY( GLUT_WINDOW_ACCUM_RED_SIZE,      GLX_ACCUM_RED_SIZE      );
234     GLX_QUERY( GLUT_WINDOW_ACCUM_GREEN_SIZE,    GLX_ACCUM_GREEN_SIZE    );
235     GLX_QUERY( GLUT_WINDOW_ACCUM_BLUE_SIZE,     GLX_ACCUM_BLUE_SIZE     );
236     GLX_QUERY( GLUT_WINDOW_ACCUM_ALPHA_SIZE,    GLX_ACCUM_ALPHA_SIZE    );
237     GLX_QUERY( GLUT_WINDOW_STEREO,              GLX_STEREO              );
238
239 #   undef GLX_QUERY
240
241     /* Colormap size is handled in a bit different way than all the rest */
242     case GLUT_WINDOW_COLORMAP_SIZE:
243         if( (fghGetConfig( GLX_RGBA )) || (fgStructure.CurrentWindow == NULL) )
244         {
245             /*
246              * We've got a RGBA visual, so there is no colormap at all.
247              * The other possibility is that we have no current window set.
248              */
249             return 0;
250         }
251         else
252         {
253           const GLXFBConfig * fbconfig =
254                 fgStructure.CurrentWindow->Window.FBConfig;
255
256           XVisualInfo * visualInfo =
257                 glXGetVisualFromFBConfig( fgDisplay.Display, *fbconfig );
258
259           const int result = visualInfo->visual->map_entries;
260
261           XFree(visualInfo);
262
263           return result;
264         }
265
266     /*
267      * Those calls are somewhat similiar, as they use XGetWindowAttributes()
268      * function
269      */
270     case GLUT_WINDOW_X:
271     case GLUT_WINDOW_Y:
272     case GLUT_WINDOW_BORDER_WIDTH:
273     case GLUT_WINDOW_HEADER_HEIGHT:
274     {
275         int x, y;
276         Window w;
277
278         if( fgStructure.CurrentWindow == NULL )
279             return 0;
280
281         XTranslateCoordinates(
282             fgDisplay.Display,
283             fgStructure.CurrentWindow->Window.Handle,
284             fgDisplay.RootWindow,
285             0, 0, &x, &y, &w);
286
287         switch ( eWhat )
288         {
289         case GLUT_WINDOW_X: return x;
290         case GLUT_WINDOW_Y: return y;
291         }
292
293         if ( w == 0 )
294             return 0;
295         XTranslateCoordinates(
296             fgDisplay.Display,
297             fgStructure.CurrentWindow->Window.Handle,
298             w, 0, 0, &x, &y, &w);
299
300         switch ( eWhat )
301         {
302         case GLUT_WINDOW_BORDER_WIDTH:  return x;
303         case GLUT_WINDOW_HEADER_HEIGHT: return y;
304         }
305     }
306
307     case GLUT_WINDOW_WIDTH:
308     case GLUT_WINDOW_HEIGHT:
309     {
310         XWindowAttributes winAttributes;
311
312         if( fgStructure.CurrentWindow == NULL )
313             return 0;
314         XGetWindowAttributes(
315             fgDisplay.Display,
316             fgStructure.CurrentWindow->Window.Handle,
317             &winAttributes
318         );
319         switch ( eWhat )
320         {
321         case GLUT_WINDOW_WIDTH:            return winAttributes.width ;
322         case GLUT_WINDOW_HEIGHT:           return winAttributes.height ;
323         }
324     }
325
326     /* I do not know yet if there will be a fgChooseVisual() function for Win32 */
327     case GLUT_DISPLAY_MODE_POSSIBLE:
328     {
329         /*  We should not have to call fgChooseFBConfig again here.  */
330         GLXFBConfig * fbconfig;
331         int isPossible;
332
333         fbconfig = fgChooseFBConfig();
334
335         if (fbconfig == NULL)
336         {
337             isPossible = 0;
338         }
339         else
340         {
341             isPossible = 1;
342             XFree(fbconfig);
343         }
344
345         return isPossible;
346     }
347
348     /* This is system-dependant */
349     case GLUT_WINDOW_FORMAT_ID:
350         if( fgStructure.CurrentWindow == NULL )
351             return 0;
352
353         return fghGetConfig( GLX_VISUAL_ID );
354
355 #elif TARGET_HOST_MS_WINDOWS
356
357     case GLUT_WINDOW_NUM_SAMPLES:
358       glGetIntegerv(WGL_SAMPLES_ARB, &nsamples);
359       return nsamples;
360
361     /* Handle the OpenGL inquiries */
362     case GLUT_WINDOW_RGBA:
363       glGetBooleanv ( GL_RGBA_MODE, &boolValue );
364       returnValue = boolValue ? 1 : 0;
365       return returnValue;
366     case GLUT_WINDOW_DOUBLEBUFFER:
367       glGetBooleanv ( GL_DOUBLEBUFFER, &boolValue );
368       returnValue = boolValue ? 1 : 0;
369       return returnValue;
370     case GLUT_WINDOW_STEREO:
371       glGetBooleanv ( GL_STEREO, &boolValue );
372       returnValue = boolValue ? 1 : 0;
373       return returnValue;
374
375     case GLUT_WINDOW_RED_SIZE:
376       glGetIntegerv ( GL_RED_BITS, &returnValue );
377       return returnValue;
378     case GLUT_WINDOW_GREEN_SIZE:
379       glGetIntegerv ( GL_GREEN_BITS, &returnValue );
380       return returnValue;
381     case GLUT_WINDOW_BLUE_SIZE:
382       glGetIntegerv ( GL_BLUE_BITS, &returnValue );
383       return returnValue;
384     case GLUT_WINDOW_ALPHA_SIZE:
385       glGetIntegerv ( GL_ALPHA_BITS, &returnValue );
386       return returnValue;
387     case GLUT_WINDOW_ACCUM_RED_SIZE:
388       glGetIntegerv ( GL_ACCUM_RED_BITS, &returnValue );
389       return returnValue;
390     case GLUT_WINDOW_ACCUM_GREEN_SIZE:
391       glGetIntegerv ( GL_ACCUM_GREEN_BITS, &returnValue );
392       return returnValue;
393     case GLUT_WINDOW_ACCUM_BLUE_SIZE:
394       glGetIntegerv ( GL_ACCUM_BLUE_BITS, &returnValue );
395       return returnValue;
396     case GLUT_WINDOW_ACCUM_ALPHA_SIZE:
397       glGetIntegerv ( GL_ACCUM_ALPHA_BITS, &returnValue );
398       return returnValue;
399     case GLUT_WINDOW_DEPTH_SIZE:
400       glGetIntegerv ( GL_DEPTH_BITS, &returnValue );
401       return returnValue;
402
403     case GLUT_WINDOW_BUFFER_SIZE:
404       returnValue = 1 ;                                      /* ????? */
405       return returnValue;
406     case GLUT_WINDOW_STENCIL_SIZE:
407       returnValue = 0 ;                                      /* ????? */
408       return returnValue;
409
410     case GLUT_WINDOW_X:
411     case GLUT_WINDOW_Y:
412     case GLUT_WINDOW_WIDTH:
413     case GLUT_WINDOW_HEIGHT:
414     {
415         /*
416          *  There is considerable confusion about the "right thing to
417          *  do" concerning window  size and position.  GLUT itself is
418          *  not consistent between Windows and UNIX/X11; since
419          *  platform independence is a virtue for "freeglut", we
420          *  decided to break with GLUT's behaviour.
421          *
422          *  Under UNIX/X11, it is apparently not possible to get the
423          *  window border sizes in order to subtract them off the
424          *  window's initial position until some time after the window
425          *  has been created.  Therefore we decided on the following
426          *  behaviour, both under Windows and under UNIX/X11:
427          *  - When you create a window with position (x,y) and size
428          *    (w,h), the upper left hand corner of the outside of the
429          *    window is at (x,y) and the size of the drawable area  is
430          *    (w,h).
431          *  - When you query the size and position of the window--as
432          *    is happening here for Windows--"freeglut" will return
433          *    the size of the drawable area--the (w,h) that you
434          *    specified when you created the window--and the coordinates
435          *    of the upper left hand corner of the drawable
436          *    area--which is NOT the (x,y) you specified.
437          */
438
439         RECT winRect;
440
441         freeglut_return_val_if_fail( fgStructure.CurrentWindow != NULL, 0 );
442
443         /*
444          * We need to call GetWindowRect() first...
445          *  (this returns the pixel coordinates of the outside of the window)
446          */
447         GetWindowRect( fgStructure.CurrentWindow->Window.Handle, &winRect );
448
449         /* ...then we've got to correct the results we've just received... */
450
451 #if !defined(_WIN32_WCE)
452         if ( ( fgStructure.GameModeWindow != fgStructure.CurrentWindow ) && ( fgStructure.CurrentWindow->Parent == NULL ) &&
453              ( ! fgStructure.CurrentWindow->IsMenu ) )
454         {
455           winRect.left   += GetSystemMetrics( SM_CXSIZEFRAME );
456           winRect.right  -= GetSystemMetrics( SM_CXSIZEFRAME );
457           winRect.top    += GetSystemMetrics( SM_CYSIZEFRAME ) + GetSystemMetrics( SM_CYCAPTION );
458           winRect.bottom -= GetSystemMetrics( SM_CYSIZEFRAME );
459         }
460 #endif /* !defined(_WIN32_WCE) */
461
462         switch( eWhat )
463         {
464         case GLUT_WINDOW_X:      return winRect.left                ;
465         case GLUT_WINDOW_Y:      return winRect.top                 ;
466         case GLUT_WINDOW_WIDTH:  return winRect.right - winRect.left;
467         case GLUT_WINDOW_HEIGHT: return winRect.bottom - winRect.top;
468         }
469     }
470     break;
471
472     case GLUT_WINDOW_BORDER_WIDTH :
473 #if defined(_WIN32_WCE)
474         return 0;
475 #else
476         return GetSystemMetrics( SM_CXSIZEFRAME );
477 #endif /* !defined(_WIN32_WCE) */
478
479     case GLUT_WINDOW_HEADER_HEIGHT :
480 #if defined(_WIN32_WCE)
481         return 0;
482 #else
483         return GetSystemMetrics( SM_CYCAPTION );
484 #endif /* defined(_WIN32_WCE) */
485
486     case GLUT_DISPLAY_MODE_POSSIBLE:
487 #if defined(_WIN32_WCE)
488         return 0;
489 #else
490         return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,
491                                     PFD_MAIN_PLANE );
492 #endif /* defined(_WIN32_WCE) */
493
494
495     case GLUT_WINDOW_FORMAT_ID:
496 #if !defined(_WIN32_WCE)
497         if( fgStructure.CurrentWindow != NULL )
498             return GetPixelFormat( fgStructure.CurrentWindow->Window.Device );
499 #endif /* defined(_WIN32_WCE) */
500         return 0;
501
502 #endif
503
504     /* The window structure queries */
505     case GLUT_WINDOW_PARENT:
506         if( fgStructure.CurrentWindow         == NULL ) return 0;
507         if( fgStructure.CurrentWindow->Parent == NULL ) return 0;
508         return fgStructure.CurrentWindow->Parent->ID;
509
510     case GLUT_WINDOW_NUM_CHILDREN:
511         if( fgStructure.CurrentWindow == NULL )
512             return 0;
513         return fgListLength( &fgStructure.CurrentWindow->Children );
514
515     case GLUT_WINDOW_CURSOR:
516         if( fgStructure.CurrentWindow == NULL )
517             return 0;
518         return fgStructure.CurrentWindow->State.Cursor;
519
520     case GLUT_MENU_NUM_ITEMS:
521         if( fgStructure.CurrentMenu == NULL )
522             return 0;
523         return fgListLength( &fgStructure.CurrentMenu->Entries );
524
525     case GLUT_ACTION_ON_WINDOW_CLOSE:
526         return fgState.ActionOnWindowClose;
527
528     case GLUT_VERSION :
529         return VERSION_MAJOR * 10000 + VERSION_MINOR * 100 + VERSION_PATCH;
530
531     case GLUT_RENDERING_CONTEXT:
532         return fgState.UseCurrentContext ? GLUT_USE_CURRENT_CONTEXT
533                                          : GLUT_CREATE_NEW_CONTEXT;
534
535     case GLUT_DIRECT_RENDERING:
536         return fgState.DirectContext;
537         break;
538
539     case GLUT_FULL_SCREEN:
540         return fghCheckFullScreen();
541         break;
542
543     default:
544         fgWarning( "glutGet(): missing enum handle %d", eWhat );
545         break;
546     }
547     return -1;
548 }
549
550 /*
551  * Returns various device information.
552  */
553 int FGAPIENTRY glutDeviceGet( GLenum eWhat )
554 {
555     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutDeviceGet" );
556
557     /* XXX WARNING: we are mostly lying in this function. */
558     switch( eWhat )
559     {
560     case GLUT_HAS_KEYBOARD:
561         /*
562          * Win32 is assumed a keyboard, and this cannot be queried,
563          * except for WindowsCE.
564          *
565          * X11 has a core keyboard by definition, although it can
566          * be present as a virtual/dummy keyboard. For now, there
567          * is no reliable way to tell if a real keyboard is present.
568          */
569 #if defined(_WIN32_CE)
570         return ( GetKeyboardStatus() & KBDI_KEYBOARD_PRESENT ) ? 1 : 0;
571 #   if FREEGLUT_LIB_PRAGMAS
572 #       pragma comment (lib,"Kbdui.lib")
573 #   endif
574
575 #else
576         return 1;
577 #endif
578
579 #if TARGET_HOST_POSIX_X11
580
581     /* X11 has a mouse by definition */
582     case GLUT_HAS_MOUSE:
583         return 1 ;
584
585     case GLUT_NUM_MOUSE_BUTTONS:
586         /* We should be able to pass NULL when the last argument is zero,
587          * but at least one X server has a bug where this causes a segfault.
588          *
589          * In XFree86/Xorg servers, a mouse wheel is seen as two buttons
590          * rather than an Axis; "freeglut_main.c" expects this when
591          * checking for a wheel event.
592          */
593         {
594             unsigned char map;
595             int nbuttons = XGetPointerMapping(fgDisplay.Display, &map,0);
596             return nbuttons;
597         }
598
599 #elif TARGET_HOST_MS_WINDOWS
600
601     case GLUT_HAS_MOUSE:
602         /*
603          * MS Windows can be booted without a mouse.
604          */
605         return GetSystemMetrics( SM_MOUSEPRESENT );
606
607     case GLUT_NUM_MOUSE_BUTTONS:
608 #  if defined(_WIN32_WCE)
609         return 1;
610 #  else
611         return GetSystemMetrics( SM_CMOUSEBUTTONS );
612 #  endif
613 #endif
614
615     case GLUT_HAS_JOYSTICK:
616         return fgJoystickDetect ();
617
618     case GLUT_OWNS_JOYSTICK:
619         return fgState.JoysticksInitialised;
620
621     case GLUT_JOYSTICK_POLL_RATE:
622         return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.JoystickPollRate : 0;
623
624     /* XXX The following two are only for Joystick 0 but this is an improvement */
625     case GLUT_JOYSTICK_BUTTONS:
626         return glutJoystickGetNumButtons ( 0 );
627
628     case GLUT_JOYSTICK_AXES:
629         return glutJoystickGetNumAxes ( 0 );
630
631     case GLUT_HAS_DIAL_AND_BUTTON_BOX:
632         return fgInputDeviceDetect ();
633
634     case GLUT_NUM_DIALS:
635         if ( fgState.InputDevsInitialised ) return 8;
636         return 0;
637  
638     case GLUT_NUM_BUTTON_BOX_BUTTONS:
639         return 0;
640
641     case GLUT_HAS_SPACEBALL:
642     case GLUT_HAS_TABLET:
643         return 0;
644
645     case GLUT_NUM_SPACEBALL_BUTTONS:
646     case GLUT_NUM_TABLET_BUTTONS:
647         return 0;
648
649     case GLUT_DEVICE_IGNORE_KEY_REPEAT:
650         return fgStructure.CurrentWindow ? fgStructure.CurrentWindow->State.IgnoreKeyRepeat : 0;
651
652     case GLUT_DEVICE_KEY_REPEAT:
653         return fgState.KeyRepeat;
654
655     default:
656         fgWarning( "glutDeviceGet(): missing enum handle %d", eWhat );
657         break;
658     }
659
660     /* And now -- the failure. */
661     return -1;
662 }
663
664 /*
665  * This should return the current state of ALT, SHIFT and CTRL keys.
666  */
667 int FGAPIENTRY glutGetModifiers( void )
668 {
669     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutGetModifiers" );
670     if( fgState.Modifiers == INVALID_MODIFIERS )
671     {
672         fgWarning( "glutGetModifiers() called outside an input callback" );
673         return 0;
674     }
675
676     return fgState.Modifiers;
677 }
678
679 /*
680  * Return the state of the GLUT API overlay subsystem. A misery ;-)
681  */
682 int FGAPIENTRY glutLayerGet( GLenum eWhat )
683 {
684     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLayerGet" );
685
686     /*
687      * This is easy as layers are not implemented ;-)
688      *
689      * XXX Can we merge the UNIX/X11 and WIN32 sections?  Or
690      * XXX is overlay support planned?
691      */
692     switch( eWhat )
693     {
694
695 #if TARGET_HOST_POSIX_X11
696
697     case GLUT_OVERLAY_POSSIBLE:
698         return 0;
699
700     case GLUT_LAYER_IN_USE:
701         return GLUT_NORMAL;
702
703     case GLUT_HAS_OVERLAY:
704         return 0;
705
706     case GLUT_TRANSPARENT_INDEX:
707         /*
708          * Return just anything, which is always defined as zero
709          *
710          * XXX HUH?
711          */
712         return 0;
713
714     case GLUT_NORMAL_DAMAGED:
715         /* XXX Actually I do not know. Maybe. */
716         return 0;
717
718     case GLUT_OVERLAY_DAMAGED:
719         return -1;
720
721 #elif TARGET_HOST_MS_WINDOWS
722
723     case GLUT_OVERLAY_POSSIBLE:
724 /*      return fgSetupPixelFormat( fgStructure.CurrentWindow, GL_TRUE,
725                                    PFD_OVERLAY_PLANE ); */
726       return 0 ;
727
728     case GLUT_LAYER_IN_USE:
729         return GLUT_NORMAL;
730
731     case GLUT_HAS_OVERLAY:
732         return 0;
733
734     case GLUT_TRANSPARENT_INDEX:
735         /*
736          * Return just anything, which is always defined as zero
737          *
738          * XXX HUH?
739          */
740         return 0;
741
742     case GLUT_NORMAL_DAMAGED:
743         /* XXX Actually I do not know. Maybe. */
744         return 0;
745
746     case GLUT_OVERLAY_DAMAGED:
747         return -1;
748 #endif
749
750     default:
751         fgWarning( "glutLayerGet(): missing enum handle %d", eWhat );
752         break;
753     }
754
755     /* And fail. That's good. Programs do love failing. */
756     return -1;
757 }
758
759 int * FGAPIENTRY glutGetModeValues(GLenum eWhat, int * size)
760 {
761   int * array;
762
763 #if TARGET_HOST_POSIX_X11
764   int attributes[9];
765   GLXFBConfig * fbconfigArray;  /*  Array of FBConfigs  */
766   int fbconfigArraySize;        /*  Number of FBConfigs in the array  */
767   int attribute_name = 0;
768 #endif
769
770   FREEGLUT_EXIT_IF_NOT_INITIALISED("glutGetModeValues");
771
772   array = NULL;
773   *size = 0;
774
775   switch (eWhat)
776     {
777 #if TARGET_HOST_POSIX_X11
778     case GLUT_AUX:
779     case GLUT_MULTISAMPLE:
780
781       attributes[0] = GLX_BUFFER_SIZE;
782       attributes[1] = GLX_DONT_CARE;
783
784       switch (eWhat)
785         {
786         case GLUT_AUX:
787           /*
788             FBConfigs are now sorted by increasing number of auxiliary
789             buffers.  We want at least one buffer.
790           */
791           attributes[2] = GLX_AUX_BUFFERS;
792           attributes[3] = 1;
793           attributes[4] = None;
794
795           attribute_name = GLX_AUX_BUFFERS;
796
797           break;
798
799
800         case GLUT_MULTISAMPLE:
801           attributes[2] = GLX_AUX_BUFFERS;
802           attributes[3] = GLX_DONT_CARE;
803           attributes[4] = GLX_SAMPLE_BUFFERS;
804           attributes[5] = 1;
805           /*
806             FBConfigs are now sorted by increasing number of samples per
807             pixel.  We want at least one sample.
808           */
809           attributes[6] = GLX_SAMPLES;
810           attributes[7] = 1;
811           attributes[8] = None;
812
813           attribute_name = GLX_SAMPLES;
814
815           break;
816         }
817
818       fbconfigArray = glXChooseFBConfig(fgDisplay.Display,
819                                         fgDisplay.Screen,
820                                         attributes,
821                                         &fbconfigArraySize);
822
823       if (fbconfigArray != NULL)
824         {
825           int * temp_array;
826           int result;   /*  Returned by glXGetFBConfigAttrib. Not checked.  */
827           int previous_value;
828           int i;
829
830           temp_array = malloc(sizeof(int) * fbconfigArraySize);
831           previous_value = 0;
832
833           for (i = 0; i < fbconfigArraySize; i++)
834             {
835               int value;
836
837               result = glXGetFBConfigAttrib(fgDisplay.Display,
838                                             fbconfigArray[i],
839                                             attribute_name,
840                                             &value);
841               if (value > previous_value)
842                 {
843                   temp_array[*size] = value;
844                   previous_value = value;
845                   (*size)++;
846                 }
847             }
848
849           array = malloc(sizeof(int) * (*size));
850           for (i = 0; i < *size; i++)
851             {
852               array[i] = temp_array[i];
853             }
854
855           free(temp_array);
856           XFree(fbconfigArray);
857         }
858
859       break;
860 #endif      
861
862     default:
863       break;
864     }
865
866   return array;
867 }
868
869 /*** END OF FILE ***/