From: Rcmaniac25 Date: Fri, 24 Jan 2014 10:26:20 +0000 (+0000) Subject: Can use input devices from x11 (serial input... unlikely to ever be used, but you... X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=commitdiff_plain;h=1f67274c9ebf2ed21d6302af23175a24ed56c820;p=freeglut Can use input devices from x11 (serial input... unlikely to ever be used, but you never know) Fixed bug in fg_window_egl:fgPlatformSetWindow where a NULL window may be passed and cause a segfault Fixed bug where navigator events were never started Take into account DisplayMode when creating window buffers Proper fgPlatformSystemTime implementation (from fg_main_x11) Added support for mutlitouch (from fg_main_windows) git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@1650 7f0cb862-5218-0410-a997-914c9d46530a --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 428b6da..f2dd875 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,7 +123,6 @@ ELSEIF(ANDROID OR BLACKBERRY) src/android/fg_cursor_android.c src/android/fg_ext_android.c src/android/fg_gamemode_android.c - src/android/fg_input_devices_android.c src/android/fg_joystick_android.c src/android/fg_spaceball_android.c src/android/fg_structure_android.c @@ -134,6 +133,7 @@ ELSEIF(ANDROID OR BLACKBERRY) src/android/native_app_glue/android_native_app_glue.h src/android/fg_init_android.c src/android/fg_internal_android.h + src/android/fg_input_devices_android.c src/android/fg_main_android.c src/android/fg_main_android.h src/android/fg_runtime_android.c @@ -144,6 +144,7 @@ ELSEIF(ANDROID OR BLACKBERRY) LIST(APPEND FREEGLUT_SRCS src/blackberry/fg_init_blackberry.c src/blackberry/fg_internal_blackberry.h + src/x11/fg_input_devices_x11.c src/blackberry/fg_main_blackberry.c src/blackberry/fg_main_blackberry.h src/blackberry/fg_state_blackberry.c diff --git a/src/blackberry/fg_init_blackberry.c b/src/blackberry/fg_init_blackberry.c index 4dee11d..40b1ed6 100644 --- a/src/blackberry/fg_init_blackberry.c +++ b/src/blackberry/fg_init_blackberry.c @@ -29,11 +29,15 @@ #include "fg_init.h" #include "egl/fg_init_egl.h" #include +#include void fgPlatformInitialize() { bps_initialize(); + navigator_request_events(0); + //XXX rotation lock? navigator_rotation_lock(true); + fghPlatformInitializeEGL(); /* Get start time */ @@ -46,6 +50,8 @@ void fgPlatformCloseDisplay() { fghPlatformCloseDisplayEGL(); + navigator_stop_events(0); + bps_shutdown(); } diff --git a/src/blackberry/fg_main_blackberry.c b/src/blackberry/fg_main_blackberry.c index 82a2705..52b36f8 100644 --- a/src/blackberry/fg_main_blackberry.c +++ b/src/blackberry/fg_main_blackberry.c @@ -139,11 +139,18 @@ unsigned char key_ascii(int qnxKeycode) return qnxKeycode; } -uint64_t fgPlatformSystemTime ( void ) +//From fg_main_x11 +fg_time_t fgPlatformSystemTime ( void ) { - struct timespec now; - clock_gettime(CLOCK_REALTIME, &now); - return (1000 * now.tv_sec) + (now.tv_nsec / 1000000); +#ifdef CLOCK_MONOTONIC + struct timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + return now.tv_nsec/1000000 + now.tv_sec*1000; +#elif defined(HAVE_GETTIMEOFDAY) + struct timeval now; + gettimeofday( &now, NULL ); + return now.tv_usec/1000 + now.tv_sec*1000; +#endif } /* @@ -276,11 +283,23 @@ void fgPlatformProcessSingleEvent ( void ) { mtouch_event_t touchEvent; screen_get_mtouch_event(screenEvent, &touchEvent, 0); - if(touchEvent.contact_id == 0) { //XXX Only support one contact for now + if(touchEvent.contact_id == 0) { int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window); } + + //Now handle mutlitouch (adapted from fg_main_windows) + if (eventType == SCREEN_EVENT_MTOUCH_TOUCH) { + INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_ENTERED ) ); + INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_DOWN ) ); + } else if (eventType == SCREEN_EVENT_MTOUCH_MOVE) { + INVOKE_WCB( *window, MultiMotion, ( touchEvent.contact_id, touchEvent.x, touchEvent.y ) ); + //XXX No motion is performed without contact, thus MultiPassive is never used + } else if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) { + INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_UP ) ); + INVOKE_WCB( *window, MultiEntry, ( touchEvent.contact_id, GLUT_LEFT ) ); + } break; } @@ -290,15 +309,19 @@ void fgPlatformProcessSingleEvent ( void ) static int mouse_pressed = 0; int buttons; int position[2]; + int wheel; // A move event will be fired unless a button state changed. bool move = true; bool left_move = false; // This is a mouse move event, it is applicable to a device with a usb mouse or simulator. screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); int size[2]; screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + //XXX Should multitouch be handled? + // Handle left mouse. Interpret as touch if the left mouse event is not consumed. if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { @@ -344,6 +367,11 @@ void fgPlatformProcessSingleEvent ( void ) if (left_move || move) { handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window); } + + if (wheel) { + fgState.MouseWheelTicks -= wheel; + //TODO: Implement wheel support (based on fg_main_mswin... though it seems excessive) + } break; } diff --git a/src/blackberry/fg_main_blackberry.h b/src/blackberry/fg_main_blackberry.h index 4ccbc3d..769e23d 100644 --- a/src/blackberry/fg_main_blackberry.h +++ b/src/blackberry/fg_main_blackberry.h @@ -30,7 +30,6 @@ #include "fg_internal.h" extern void fgPlatformProcessSingleEvent(void); -extern uint64_t fgPlatformSystemTime(void); extern void fgPlatformSleepForEvents(uint64_t msec); extern void fgPlatformMainLoopPreliminaryWork(void); diff --git a/src/blackberry/fg_window_blackberry.c b/src/blackberry/fg_window_blackberry.c index 08f6643..7d2eb49 100644 --- a/src/blackberry/fg_window_blackberry.c +++ b/src/blackberry/fg_window_blackberry.c @@ -98,7 +98,7 @@ void fgPlatformOpenWindow( SFG_Window* window, const char* title, }*/ /* Create window buffers */ - if (screen_create_window_buffers(sWindow, 2)) { + if (screen_create_window_buffers(sWindow, (fgState.DisplayMode & GLUT_DOUBLE) ? 2 : 1)) { screen_destroy_window(sWindow); screen_destroy_context(window->Window.pContext.screenContext); fgError("Could not create window buffers"); diff --git a/src/egl/fg_window_egl.c b/src/egl/fg_window_egl.c index 48eb748..6c4a7de 100644 --- a/src/egl/fg_window_egl.c +++ b/src/egl/fg_window_egl.c @@ -46,7 +46,7 @@ int fghChooseConfig(EGLConfig* config) { EGL_SAMPLES, (fgState.DisplayMode & GLUT_MULTISAMPLE) ? fgState.SampleNumber : 0, EGL_NONE }; - + EGLint num_config; if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display, attribs, config, 1, &num_config)) { @@ -94,11 +94,13 @@ EGLContext fghCreateNewContextEGL( SFG_Window* window ) { void fgPlatformSetWindow ( SFG_Window *window ) { - if (eglMakeCurrent(fgDisplay.pDisplay.egl.Display, - window->Window.pContext.egl.Surface, - window->Window.pContext.egl.Surface, - window->Window.Context) == EGL_FALSE) - fgError("eglMakeCurrent: err=%x\n", eglGetError()); + if ( window != fgStructure.CurrentWindow && window) { + if (eglMakeCurrent(fgDisplay.pDisplay.egl.Display, + window->Window.pContext.egl.Surface, + window->Window.pContext.egl.Surface, + window->Window.Context) == EGL_FALSE) + fgError("eglMakeCurrent: err=%x\n", eglGetError()); + } } /*