Moving the platform-specific window state fields into their own substructure
[freeglut] / src / Common / freeglut_main.c
index e7b4cb8..66281ea 100644 (file)
@@ -70,18 +70,12 @@ struct GXKeyList gxKeyList;
 #    define MIN(a,b) (((a)<(b)) ? (a) : (b))\r
 #endif\r
 \r
-#ifdef WM_TOUCH\r
-    typedef BOOL (WINAPI *pGetTouchInputInfo)(HTOUCHINPUT,UINT,PTOUCHINPUT,int);\r
-    typedef BOOL (WINAPI *pCloseTouchInputHandle)(HTOUCHINPUT);\r
-       static pGetTouchInputInfo fghGetTouchInputInfo = (pGetTouchInputInfo)0xDEADBEEF;\r
-       static pCloseTouchInputHandle fghCloseTouchInputHandle = (pCloseTouchInputHandle)0xDEADBEEF;\r
-#endif\r
-\r
-extern void fghPlatformReshapeWindow ( SFG_Window *window, int width, int height );\r
-extern void fghcbPlatformDisplayWindow ( SFG_Window *window );\r
-extern void fghPlatformSleepForEvents( long msec );\r
-extern void fghProcessSingleEvent ( void );\r
-extern void fghMainLoopPreliminaryWork ( void );\r
+extern void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height );\r
+extern void fgPlatformDisplayWindow ( SFG_Window *window );\r
+extern unsigned long fgPlatformSystemTime ( void );\r
+extern void fgPlatformSleepForEvents( long msec );\r
+extern void fgPlatformProcessSingleEvent ( void );\r
+extern void fgPlatformMainLoopPreliminaryWork ( void );\r
 \r
 \r
 /*\r
@@ -103,11 +97,11 @@ extern void fghMainLoopPreliminaryWork ( void );
  * match the new window size.\r
  */\r
 #if TARGET_HOST_POSIX_X11\r
-static void fghPlatformReshapeWindow ( SFG_Window *window, int width, int height )\r
+void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height )\r
 {\r
-    XResizeWindow( fgDisplay.Display, window->Window.Handle,\r
+    XResizeWindow( fgDisplay.pDisplay.Display, window->Window.Handle,\r
                    width, height );\r
-    XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */\r
+    XFlush( fgDisplay.pDisplay.Display ); /* XXX Shouldn't need this */\r
 }\r
 #endif\r
 \r
@@ -117,7 +111,7 @@ static void fghReshapeWindow ( SFG_Window *window, int width, int height )
 \r
     freeglut_return_if_fail( window != NULL );\r
 \r
-       fghPlatformReshapeWindow ( window, width, height );\r
+       fgPlatformReshapeWindow ( window, width, height );\r
 \r
     if( FETCH_WCB( *window, Reshape ) )\r
         INVOKE_WCB( *window, Reshape, ( width, height ) );\r
@@ -177,10 +171,20 @@ void fghRedrawWindow ( SFG_Window *window )
  * A static helper function to execute display callback for a window\r
  */\r
 #if TARGET_HOST_POSIX_X11\r
-static void fghcbPlatformDisplayWindow ( SFG_Window *window )\r
+void fgPlatformDisplayWindow ( SFG_Window *window )\r
 {\r
         fghRedrawWindow ( window ) ;\r
 }\r
+\r
+\r
+unsigned long fgPlatformSystemTime ( void )\r
+{\r
+#if TARGET_HOST_SOLARIS || HAVE_GETTIMEOFDAY\r
+    struct timeval now;\r
+    gettimeofday( &now, NULL );\r
+    return now.tv_usec/1000 + now.tv_sec*1000;\r
+#endif\r
+}\r
 #endif\r
 \r
 static void fghcbDisplayWindow( SFG_Window *window,\r
@@ -190,7 +194,7 @@ static void fghcbDisplayWindow( SFG_Window *window,
         window->State.Visible )\r
     {\r
         window->State.Redisplay = GL_FALSE;\r
-               fghcbPlatformDisplayWindow ( window );\r
+               fgPlatformDisplayWindow ( window );\r
     }\r
 \r
     fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );\r
@@ -269,18 +273,9 @@ static void fghCheckTimers( void )
  * when subtracting an initial start time, unless the total time exceeds\r
  * 32-bit, where the GLUT API return value is also overflowed.\r
  */  \r
-unsigned long fgSystemTime(void) {\r
-#if TARGET_HOST_SOLARIS || HAVE_GETTIMEOFDAY\r
-    struct timeval now;\r
-    gettimeofday( &now, NULL );\r
-    return now.tv_usec/1000 + now.tv_sec*1000;\r
-#elif TARGET_HOST_MS_WINDOWS\r
-#    if defined(_WIN32_WCE)\r
-    return GetTickCount();\r
-#    else\r
-    return timeGetTime();\r
-#    endif\r
-#endif\r
+unsigned long fgSystemTime(void)\r
+{\r
+       return fgPlatformSystemTime ();\r
 }\r
   \r
 /*\r
@@ -423,7 +418,7 @@ static long fghNextTimer( void )
  */\r
 \r
 #if TARGET_HOST_POSIX_X11\r
-static void fghPlatformSleepForEvents( long msec )\r
+void fgPlatformSleepForEvents( long msec )\r
 {\r
     /*\r
      * Possibly due to aggressive use of XFlush() and friends,\r
@@ -434,14 +429,14 @@ static void fghPlatformSleepForEvents( long msec )
      * need to allow that we may have an empty socket but non-\r
      * empty event queue.\r
      */\r
-    if( ! XPending( fgDisplay.Display ) )\r
+    if( ! XPending( fgDisplay.pDisplay.Display ) )\r
     {\r
         fd_set fdset;\r
         int err;\r
         int socket;\r
         struct timeval wait;\r
 \r
-        socket = ConnectionNumber( fgDisplay.Display );\r
+        socket = ConnectionNumber( fgDisplay.pDisplay.Display );\r
         FD_ZERO( &fdset );\r
         FD_SET( socket, &fdset );\r
         wait.tv_sec = msec / 1000;\r
@@ -469,14 +464,14 @@ static void fghSleepForEvents( void )
     if( fghHaveJoystick( ) && ( msec > 10 ) )     \r
         msec = 10;\r
 \r
-       fghPlatformSleepForEvents ( msec );\r
+       fgPlatformSleepForEvents ( msec );\r
 }\r
 \r
 #if TARGET_HOST_POSIX_X11\r
 /*\r
  * Returns GLUT modifier mask for the state field of an X11 event.\r
  */\r
-int fghGetModifiers( int state )\r
+int fgPlatformGetModifiers( int state )\r
 {\r
     int ret = 0;\r
 \r
@@ -933,7 +928,7 @@ static void fghPrintEvent( XEvent *event )
 }\r
 \r
 \r
-void fghProcessSingleEvent ( void )\r
+void fgPlatformProcessSingleEvent ( void )\r
 {\r
     SFG_Window* window;\r
     XEvent event;\r
@@ -950,9 +945,9 @@ void fghProcessSingleEvent ( void )
 \r
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );\r
 \r
-    while( XPending( fgDisplay.Display ) )\r
+    while( XPending( fgDisplay.pDisplay.Display ) )\r
     {\r
-        XNextEvent( fgDisplay.Display, &event );\r
+        XNextEvent( fgDisplay.pDisplay.Display, &event );\r
 #if _DEBUG\r
         fghPrintEvent( &event );\r
 #endif\r
@@ -965,7 +960,7 @@ void fghProcessSingleEvent ( void )
                 break;\r
             }\r
             /* Destroy the window when the WM_DELETE_WINDOW message arrives */\r
-            if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )\r
+            if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.pDisplay.DeleteWindow )\r
             {\r
                 GETWINDOW( xclient );\r
 \r
@@ -1006,13 +1001,13 @@ void fghProcessSingleEvent ( void )
                     height = event.xconfigure.height;\r
                 }\r
 \r
-                if( ( width != window->State.OldWidth ) ||\r
-                    ( height != window->State.OldHeight ) )\r
+                if( ( width != window->State.pWState.OldWidth ) ||\r
+                    ( height != window->State.pWState.OldHeight ) )\r
                 {\r
                     SFG_Window *current_window = fgStructure.CurrentWindow;\r
 \r
-                    window->State.OldWidth = width;\r
-                    window->State.OldHeight = height;\r
+                    window->State.pWState.OldWidth = width;\r
+                    window->State.pWState.OldHeight = height;\r
                     if( FETCH_WCB( *window, Reshape ) )\r
                         INVOKE_WCB( *window, Reshape, ( width, height ) );\r
                     else\r
@@ -1147,7 +1142,7 @@ void fghProcessSingleEvent ( void )
              * XXX track ButtonPress/ButtonRelease events in our own\r
              * XXX bit-mask?\r
              */\r
-            fgState.Modifiers = fghGetModifiers( event.xmotion.state );\r
+            fgState.Modifiers = fgPlatformGetModifiers( event.xmotion.state );\r
             if ( event.xmotion.state & ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) ) {\r
                 INVOKE_WCB( *window, Motion, ( event.xmotion.x,\r
                                                event.xmotion.y ) );\r
@@ -1201,7 +1196,7 @@ void fghProcessSingleEvent ( void )
                 ! FETCH_WCB( *window, MouseWheel ) )\r
                 break;\r
 \r
-            fgState.Modifiers = fghGetModifiers( event.xbutton.state );\r
+            fgState.Modifiers = fgPlatformGetModifiers( event.xbutton.state );\r
 \r
             /* Finally execute the mouse or mouse wheel callback */\r
             if( ( button < glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS ) ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )\r
@@ -1263,7 +1258,7 @@ void fghProcessSingleEvent ( void )
                      */\r
 \r
                     char keys[32];\r
-                    XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */\r
+                    XQueryKeymap( fgDisplay.pDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */\r
 \r
                     if ( event.xkey.keycode<256 )            /* XQueryKeymap is limited to 256 keycodes    */\r
                     {\r
@@ -1316,7 +1311,7 @@ void fghProcessSingleEvent ( void )
                     if( keyboard_cb )\r
                     {\r
                         fgSetWindow( window );\r
-                        fgState.Modifiers = fghGetModifiers( event.xkey.state );\r
+                        fgState.Modifiers = fgPlatformGetModifiers( event.xkey.state );\r
                         keyboard_cb( asciiCode[ 0 ],\r
                                      event.xkey.x, event.xkey.y\r
                         );\r
@@ -1385,7 +1380,7 @@ void fghProcessSingleEvent ( void )
                     if( special_cb && (special != -1) )\r
                     {\r
                         fgSetWindow( window );\r
-                        fgState.Modifiers = fghGetModifiers( event.xkey.state );\r
+                        fgState.Modifiers = fgPlatformGetModifiers( event.xkey.state );\r
                         special_cb( special, event.xkey.x, event.xkey.y );\r
                         fgState.Modifiers = INVALID_MODIFIERS;\r
                     }\r
@@ -1412,7 +1407,7 @@ void fghProcessSingleEvent ( void )
 }\r
 \r
 \r
-static void fghMainLoopPreliminaryWork ( void )\r
+void fgPlatformMainLoopPreliminaryWork ( void )\r
 {\r
 }\r
 #endif\r
@@ -1424,7 +1419,7 @@ static void fghMainLoopPreliminaryWork ( void )
  */\r
 void FGAPIENTRY glutMainLoopEvent( void )\r
 {\r
-       fghProcessSingleEvent ();\r
+       fgPlatformProcessSingleEvent ();\r
 \r
     if( fgState.Timers.First )\r
         fghCheckTimers( );\r
@@ -1444,7 +1439,7 @@ void FGAPIENTRY glutMainLoop( void )
 \r
     FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoop" );\r
 \r
-       fghMainLoopPreliminaryWork ();\r
+       fgPlatformMainLoopPreliminaryWork ();\r
 \r
     fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;\r
     while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )\r