X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Fblackberry%2Ffg_main_blackberry.c;h=4aa6759c72cdc7eefdba487d4ea7d02eca9e0d3f;hb=265a4c1c07f001dce197024c77ecad3d6aa9b111;hp=6fc6e7cd59a8669af17b3e3cce8ee7a090715660;hpb=e3ca92b25a88aae086386edcf0141b3340be723c;p=freeglut diff --git a/src/blackberry/fg_main_blackberry.c b/src/blackberry/fg_main_blackberry.c index 6fc6e7c..4aa6759 100644 --- a/src/blackberry/fg_main_blackberry.c +++ b/src/blackberry/fg_main_blackberry.c @@ -31,15 +31,33 @@ #include "fg_internal.h" #include "egl/fg_window_egl.h" +#ifdef __PLAYBOOK__ +#include +#ifdef NDEBUG +#define LOGI(...) +#else +#define LOGI(...) ((void)slogf(1337, _SLOG_INFO, __VA_ARGS__)) +#endif +#define LOGW(...) ((void)slogf(1337, _SLOG_WARNING, __VA_ARGS__)) +#ifndef SLOG2_FA_SIGNED +#define SLOG2_FA_SIGNED(x) (x) +#endif +#else #include +#ifdef NDEBUG +#define LOGI(...) +#else #define LOGI(...) ((void)slog2fa(NULL, 1337, SLOG2_INFO, __VA_ARGS__, SLOG2_FA_END)) +#endif #define LOGW(...) ((void)slog2fa(NULL, 1337, SLOG2_WARNING, __VA_ARGS__, SLOG2_FA_END)) +#endif #include #include #include #include #include #include +#include extern void fghOnReshapeNotify(SFG_Window *window, int width, int height, GLboolean forceNotify); extern void fghOnPositionNotify(SFG_Window *window, int x, int y, GLboolean forceNotify); @@ -52,9 +70,13 @@ extern void fgPlatformHideWindow( SFG_Window *window ); extern void fgPlatformIconifyWindow( SFG_Window *window ); extern void fgPlatformShowWindow( SFG_Window *window ); extern void fgPlatformMainLoopPostWork ( void ); +extern void fgPlatformRotateWindow( SFG_Window *window, int rotation ); +extern void fgPlatformFlushCommands ( void ); static struct touchscreen touchscreen; +#define ESCAPE_BUTTON_KEY 0x001B + unsigned int key_special(int qnxKeycode) { switch(qnxKeycode) { @@ -134,7 +156,7 @@ unsigned char key_ascii(int qnxKeycode) case KEYCODE_RETURN: return 0x000A; case KEYCODE_ESCAPE: - return 0x001B; + return ESCAPE_BUTTON_KEY; } } return qnxKeycode; @@ -160,8 +182,8 @@ fg_time_t fgPlatformSystemTime ( void ) */ void fgPlatformSleepForEvents( fg_time_t msec ) { - //XXX: Is this right? Is there a more direct way to access the context? - if(fgStructure.CurrentWindow && bps_get_event(&fgDisplay.pDisplay.event, (int)msec) != BPS_SUCCESS) { + if(fgStructure.CurrentWindow && fgDisplay.pDisplay.event == NULL && + bps_get_event(&fgDisplay.pDisplay.event, (int)msec) != BPS_SUCCESS) { LOGW("BPS couldn't get event"); } } @@ -264,248 +286,512 @@ int fgPlatformGetModifiers (int mod) ((mod & KEYMOD_ALT) ? GLUT_ACTIVE_ALT : 0)); } +void fgPlatformHandleKeyboardHeight(SFG_Window* window, int height) +{ + int size[2]; + int screenHeight; + int nScreenHeight = -1; + + screenHeight = glutGet(GLUT_WINDOW_HEIGHT); //Using this takes rotation into account + if(height == 0) { + nScreenHeight = screenHeight; + } + else if(!screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_POSITION, size)) { + /* Calculate the new screen size */ //XXX Make sure to use display size instead of screen size + nScreenHeight = ((size[1] + screenHeight) - height) - size[1]; + } + + if(nScreenHeight != -1) { + /* If nScreenHeight is less then zero then window is covered. If nScreenHeight == height, then no change in size. Else, change in size */ + + int screenWidth = glutGet(GLUT_WINDOW_WIDTH); + if(nScreenHeight < 0) { + LOGI("fgPlatformHandleKeyboardHeight: Covered window state"); + window->State.Visible = GL_FALSE; + window->State.pWState.windowCovered = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_COVERED)); + fghOnReshapeNotify(window, screenWidth, 0, GL_FALSE); + } else { + if(window->State.pWState.windowCovered == GL_TRUE) { + LOGI("fgPlatformHandleKeyboardHeight: Resetting window state"); + + /* Reset window status if it was previously covered */ + switch(window->State.pWState.windowState) { + case NAVIGATOR_WINDOW_FULLSCREEN: + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_RETAINED)); + break; + case NAVIGATOR_WINDOW_THUMBNAIL: + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_PARTIALLY_RETAINED)); + break; + case NAVIGATOR_WINDOW_INVISIBLE: + window->State.Visible = GL_FALSE; + INVOKE_WCB(*window, WindowStatus, (GLUT_HIDDEN)); + break; + } + window->State.pWState.windowCovered = GL_FALSE; + } + fghOnReshapeNotify(window, screenWidth, nScreenHeight, GL_FALSE); + } + } +} + void fgPlatformProcessSingleEvent ( void ) { + if(fgStructure.CurrentWindow == NULL) { + //XXX Is this right? Would this just cause a whole lot of busy looping while we wait for events? + LOGW("fgPlatformProcessSingleEvent: Missing current window. Skipping event processing"); + return; + } + + if(fgDisplay.pDisplay.event == NULL) + /* Nothing to do */ + return; + int domain; do { - if(fgDisplay.pDisplay.event != NULL) { - SFG_Window* window = fgStructure.CurrentWindow; - if (window != NULL && window->Window.Handle != NULL) { - int size[2]; - screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); - fghOnReshapeNotify(window,size[0],size[1],GL_FALSE); - } - - domain = bps_event_get_domain(fgDisplay.pDisplay.event); - if (domain == screen_get_domain()) { - int eventType; - int mod; - screen_event_t screenEvent = screen_event_get_event(fgDisplay.pDisplay.event); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType); - switch (eventType) { - - //Mostly from fg_main_android - case SCREEN_EVENT_MTOUCH_TOUCH: - case SCREEN_EVENT_MTOUCH_RELEASE: - case SCREEN_EVENT_MTOUCH_MOVE: - { - mtouch_event_t touchEvent; - screen_get_mtouch_event(screenEvent, &touchEvent, 0); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); + SFG_Window* window = fgStructure.CurrentWindow; + domain = bps_event_get_domain(fgDisplay.pDisplay.event); + if (domain == screen_get_domain()) { + int eventType; + int mod; + screen_event_t screenEvent = screen_event_get_event(fgDisplay.pDisplay.event); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType); + switch (eventType) { + + //Mostly from fg_main_android + case SCREEN_EVENT_MTOUCH_TOUCH: + case SCREEN_EVENT_MTOUCH_RELEASE: + case SCREEN_EVENT_MTOUCH_MOVE: + { + mtouch_event_t touchEvent; + screen_get_mtouch_event(screenEvent, &touchEvent, 0); +#ifndef __PLAYBOOK__ + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); +#else + mod = 0; +#endif - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d, Mod: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id), SLOG2_FA_SIGNED(mod)); + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d, Mod: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id), SLOG2_FA_SIGNED(mod)); - /* Remember the current modifiers state so user can query it from their callback */ - fgState.Modifiers = fgPlatformGetModifiers(mod); + /* Remember the current modifiers state so user can query it from their callback */ + fgState.Modifiers = fgPlatformGetModifiers(mod); - 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); - } + 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; + //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 ) ); } - case SCREEN_EVENT_POINTER: - { - //Based off/part taken from GamePlay3d PlatformBlackBerry - 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); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); - int size[2]; - screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + fgState.Modifiers = INVALID_MODIFIERS; + break; + } - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d, Mod: 0x%X", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel), SLOG2_FA_SIGNED(mod)); + case SCREEN_EVENT_POINTER: + { + //Based off/part taken from GamePlay3d PlatformBlackBerry + 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); +#ifndef __PLAYBOOK__ + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); +#else + wheel = mod = 0; +#endif + int size[2]; + screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); - //XXX Should multitouch be handled? + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d, Mod: 0x%X", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel), SLOG2_FA_SIGNED(mod)); - /* Remember the current modifiers state so user can query it from their callback */ - fgState.Modifiers = fgPlatformGetModifiers(mod); + //XXX Is multitouch be handled in a good way? - // 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) { - left_move = true; - } else { - move = false; - mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON; - handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_TOUCH, window); - } - } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { + /* Remember the current modifiers state so user can query it from their callback */ + fgState.Modifiers = fgPlatformGetModifiers(mod); + + // 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) { + left_move = true; + } else { move = false; - mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON; - handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_RELEASE, window); + mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON; + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_TOUCH, window); } + } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON; + handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_RELEASE, window); + } - // Handle right mouse. - if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) { - if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) { - move = false; - mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_DOWN, position[0], position[1])); - } - } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) { + // Handle right mouse. + if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) { + if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) { move = false; - mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_UP, position[0], position[1])); + mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_DOWN, position[0], position[1])); } + } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_UP, position[0], position[1])); + } - // Handle middle mouse. - if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) { - if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) { - move = false; - mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_DOWN, position[0], position[1])); - } - } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) { + // Handle middle mouse. + if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) { + if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) { move = false; - mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON; - INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_UP, position[0], position[1])); + mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_DOWN, position[0], position[1])); } + } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) { + move = false; + mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON; + INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_UP, position[0], position[1])); + } - // Fire a move event if none of the buttons changed. - if (left_move || move) { - handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window); - } + // Fire a move event if none of the buttons changed. + 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) + if (wheel) { + /* Very slightly modified from fg_main_mswin. + * Because we don't want MouseWheel to be called every. single. time. + * That the action occurs, we mimic the Windows version with "wheel deltas" + * XXX Do we even want this? + * XXX If we want this, it's possible to get horizontal scroll as well. + * XXX -Vertical scroll=wheel 0, horizontal=wheel 1? */ + fgState.MouseWheelTicks -= wheel; + if (abs(fgState.MouseWheelTicks) >= WHEEL_DELTA) + { + int wheel_number = 0; + int direction = (fgState.MouseWheelTicks > 0) ? -1 : 1; + + if (!FETCH_WCB(*window, MouseWheel) && !FETCH_WCB(*window, Mouse)) + break; + + //XXX fgSetWindow(window); + + while(abs(fgState.MouseWheelTicks) >= WHEEL_DELTA) + { + if (FETCH_WCB(*window, MouseWheel)) + INVOKE_WCB(*window, MouseWheel, (wheel_number, direction, window->State.MouseX, window->State.MouseY)); + else /* No mouse wheel, call the mouse button callback twice */ + { + /* + * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4 + * " " one +1 to 5, -1 to 6, ... + * + * XXX The below assumes that you have no more than 3 mouse + * XXX buttons. Sorry. + */ + int button = wheel_number * 2 + 3; + if (direction < 0) + ++button; + INVOKE_WCB(*window, Mouse, (button, GLUT_DOWN, window->State.MouseX, window->State.MouseY)); + INVOKE_WCB(*window, Mouse, (button, GLUT_UP, window->State.MouseX, window->State.MouseY)); + } + + fgState.MouseWheelTicks -= WHEEL_DELTA * direction; + } } - break; } - //Based off fg_main_android - case SCREEN_EVENT_KEYBOARD: - { - int flags; - int value; - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); - screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); - - LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X, Mod: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_SIGNED(mod)); - - /* Suppress key repeats if desired. Based off fg_main_mswin */ - if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_OFF && fgStructure.CurrentWindow->State.IgnoreKeyRepeat == GL_TRUE)) { - unsigned int keypress = 0; - unsigned char ascii = 0; - - /* Remember the current modifiers state so user can query it from their callback */ - fgState.Modifiers = fgPlatformGetModifiers(mod); - - /* Process keys */ - if ((keypress = key_special(value))) { - if(flags & KEY_DOWN) { - INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); - } else { - INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY)); - } - } else if((flags & KEY_SYM_VALID) && (ascii = key_ascii(value))) { - if(flags & KEY_DOWN) { - INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY)); - } else { - INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); - } + fgState.Modifiers = INVALID_MODIFIERS; + break; + } + + //Based off fg_main_android + case SCREEN_EVENT_KEYBOARD: + { + int flags; + int value; + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); + screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod); + + LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X, Mod: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_SIGNED(mod)); + + /* Suppress key repeats if desired. Based off fg_main_mswin */ + if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_OFF && fgStructure.CurrentWindow->State.IgnoreKeyRepeat == GL_TRUE)) { + unsigned int keypress = 0; + unsigned char ascii = 0; + + /* Remember the current modifiers state so user can query it from their callback */ + fgState.Modifiers = fgPlatformGetModifiers(mod); + + /* Process keys */ + if ((keypress = key_special(value))) { + if(flags & KEY_DOWN) { + INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY)); + } else { + INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY)); + } + } else if((flags & KEY_SYM_VALID) && (ascii = key_ascii(value))) { + if(flags & KEY_DOWN) { + INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY)); } else { - LOGW("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Unhandled key event"); + INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY)); } + } else { + LOGW("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Unhandled key event"); } - break; + + fgState.Modifiers = INVALID_MODIFIERS; } + break; + } - case SCREEN_EVENT_PROPERTY: - case SCREEN_EVENT_IDLE: - break; + case SCREEN_EVENT_PROPERTY: + case SCREEN_EVENT_IDLE: + break; - default: - LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType)); - break; - } - } else if (domain == navigator_get_domain()) { - int eventType = bps_event_get_code(fgDisplay.pDisplay.event); - switch (eventType) { + default: + LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType)); + break; + } + } else if (domain == navigator_get_domain()) { + unsigned int eventType = bps_event_get_code(fgDisplay.pDisplay.event); + switch (eventType) { - case NAVIGATOR_WINDOW_STATE: + case NAVIGATOR_WINDOW_STATE: + { + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE"); + + /* Covered only happens due to keyboard. When the app is minimized, the keyboard is closed. + When the keyboard is open, and the app is fullscreened, the keyboard is also closed. + If a window is covered and the app is minimized, the state will be set and the keyboard event + will adjust the screen size and change window status. */ + navigator_window_state_t state = navigator_event_get_window_state(fgDisplay.pDisplay.event); + if(window->State.pWState.windowCovered == GL_FALSE) { - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE"); - navigator_window_state_t state = navigator_event_get_window_state(fgDisplay.pDisplay.event); switch (state) { case NAVIGATOR_WINDOW_FULLSCREEN: LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN"); - INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_RETAINED)); break; case NAVIGATOR_WINDOW_THUMBNAIL: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL"); + window->State.Visible = GL_TRUE; + INVOKE_WCB(*window, WindowStatus, (GLUT_PARTIALLY_RETAINED)); + break; case NAVIGATOR_WINDOW_INVISIBLE: - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL/NAVIGATOR_WINDOW_INVISIBLE"); - INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_INVISIBLE"); + window->State.Visible = GL_FALSE; + INVOKE_WCB(*window, WindowStatus, (GLUT_HIDDEN)); break; default: LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); break; } - break; } + window->State.pWState.windowState = state; + break; + } - case NAVIGATOR_EXIT: - { - LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT"); + case NAVIGATOR_EXIT: + { + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT"); - fgPlatformMainLoopPostWork(); + fgPlatformMainLoopPostWork(); - /* User closed the application for good, let's kill the window */ - SFG_Window* window = fgStructure.CurrentWindow; - if (window != NULL) { - fgDestroyWindow(window); - } else { - LOGW("NAVIGATOR_EXIT: No current window"); - } - break; + /* User closed the application for good, let's kill the window */ + SFG_Window* window = fgStructure.CurrentWindow; + if (window != NULL) { + fgDestroyWindow(window); + } else { + LOGW("NAVIGATOR_EXIT: No current window"); } + break; + } - case NAVIGATOR_SWIPE_DOWN: - case NAVIGATOR_BACK: - case NAVIGATOR_WINDOW_ACTIVE: - case NAVIGATOR_WINDOW_INACTIVE: - case NAVIGATOR_KEYBOARD_STATE: - case NAVIGATOR_KEYBOARD_POSITION: - case NAVIGATOR_DEVICE_LOCK_STATE: - case NAVIGATOR_WINDOW_COVER: - case NAVIGATOR_WINDOW_COVER_ENTER: - case NAVIGATOR_WINDOW_COVER_EXIT: - case NAVIGATOR_APP_STATE: - //XXX Should probably do something with these - break; + case NAVIGATOR_SWIPE_DOWN: + /* XXX Open app menu */ + break; + + /* Orientation is a bunch of handshakes. + - First the app get's asked if it wants to rotate (NAVIGATOR_ORIENTATION_CHECK) + - If the app wants to rotate, then it will be told what size it will be after rotate (NAVIGATOR_ORIENTATION_SIZE). + - Once the OS confirms that it's ready to rotate, it tells the app to handle rotation (NAVIGATOR_ORIENTATION). + - Once rotation is complete, the OS tells the app it's done (NAVIGATOR_ORIENTATION_DONE) */ + case NAVIGATOR_ORIENTATION_CHECK: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_CHECK"); + + /* Reset sizes */ + window->State.pWState.newWidth = 0; + window->State.pWState.newHeight = 0; + + /* Notify that we want to rotate */ + navigator_orientation_check_response(fgDisplay.pDisplay.event, true); + break; + + case NAVIGATOR_ORIENTATION: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION"); + + /* NAVIGATOR_ORIENTATION occurs before NAVIGATOR_KEYBOARD_POSITION */ + + /* Rotate and resize the window */ + fgPlatformRotateWindow(window, navigator_event_get_orientation_angle(fgDisplay.pDisplay.event)); + fgPlatformFlushCommands(); +#ifdef __PLAYBOOK__ + /* PlayBook doesn't indicate what the new size will be, so we need to retrieve it from the window itself */ + window->State.pWState.newWidth = glutGet(GLUT_WINDOW_WIDTH); + window->State.pWState.newHeight = glutGet(GLUT_WINDOW_HEIGHT); +#endif + fghOnReshapeNotify(window, window->State.pWState.newWidth, window->State.pWState.newHeight, GL_FALSE); + + /* Reset sizes */ + window->State.pWState.newWidth = 0; + window->State.pWState.newHeight = 0; + + /* Done rotating */ + navigator_done_orientation(fgDisplay.pDisplay.event); + break; + + case NAVIGATOR_BACK: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_BACK"); + INVOKE_WCB(*window, Keyboard, (ESCAPE_BUTTON_KEY, window->State.MouseX, window->State.MouseY)); + INVOKE_WCB(*window, KeyboardUp, (ESCAPE_BUTTON_KEY, window->State.MouseX, window->State.MouseY)); + break; + + case NAVIGATOR_WINDOW_ACTIVE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_ACTIVE"); + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME)); + break; + + case NAVIGATOR_WINDOW_INACTIVE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_INACTIVE"); + INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE)); + break; + + case NAVIGATOR_ORIENTATION_DONE: + case NAVIGATOR_ORIENTATION_RESULT: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_DONE/NAVIGATOR_ORIENTATION_RESULT"); + break; + +#ifndef __PLAYBOOK__ + case NAVIGATOR_KEYBOARD_STATE: + { + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE"); + navigator_keyboard_state_t state = navigator_event_get_keyboard_state(fgDisplay.pDisplay.event); + switch (state) + { + case NAVIGATOR_KEYBOARD_CLOSED: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE-NAVIGATOR_KEYBOARD_CLOSED"); + /* NAVIGATOR_KEYBOARD_POSITION only occurs on open, so on keyboard close we need to reset the keyboard height */ + fgPlatformHandleKeyboardHeight(window, 0); + break; + case NAVIGATOR_KEYBOARD_OPENING: + case NAVIGATOR_KEYBOARD_OPENED: + case NAVIGATOR_KEYBOARD_CLOSING: + break; + case NAVIGATOR_KEYBOARD_UNRECOGNIZED: + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE-NAVIGATOR_KEYBOARD_UNRECOGNIZED"); + break; default: - LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType)); + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state)); break; } + break; + } + + case NAVIGATOR_KEYBOARD_POSITION: + { + /* Occurs only when keyboard has opened or resizes */ + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_POSITION"); + + int keyboardOffset = navigator_event_get_keyboard_position(fgDisplay.pDisplay.event); + if(keyboardOffset == BPS_FAILURE) { + LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_POSITION: getting keyboard offset failed"); + } else { + /* keyboardOffset is the offset from the top of the screen to the top of the keyboard, AKA the size of the uncovered screen + We want the height of the keyboard. So instead of determining the orientation, getting the right display size, and subtracting; + we just get the keyboard height which may be slower but easier to understand and work with */ + virtualkeyboard_get_height(&keyboardOffset); + fgPlatformHandleKeyboardHeight(window, keyboardOffset); + } + break; + } + + case NAVIGATOR_DEVICE_LOCK_STATE: + break; + + case NAVIGATOR_WINDOW_COVER: + case NAVIGATOR_WINDOW_COVER_ENTER: + case NAVIGATOR_WINDOW_COVER_EXIT: + /* BlackBerry specific. Let app status and window status take care of everything */ + break; + + case NAVIGATOR_APP_STATE: + /* Can do the same as NAVIGATOR_WINDOW_ACTIVE/NAVIGATOR_WINDOW_INACTIVE but + seems like it doesn't work when the app comes to the foreground. Might be a bug */ + break; + + case NAVIGATOR_ORIENTATION_SIZE: + LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_SIZE"); + + /* Get new window size */ + window->State.pWState.newWidth = navigator_event_get_orientation_size_width(fgDisplay.pDisplay.event); + window->State.pWState.newHeight = navigator_event_get_orientation_size_height(fgDisplay.pDisplay.event); + break; +#endif + + case 0: //Doesn't exist in header, but shows up when keyboard shows and resizes + break; + + default: + LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType)); + break; } } +#ifdef __PLAYBOOK__ + else if(domain == virtualkeyboard_get_domain()) { + unsigned int eventType = bps_event_get_code(fgDisplay.pDisplay.event); + switch (eventType) { + case VIRTUALKEYBOARD_EVENT_VISIBLE: + break; + + case VIRTUALKEYBOARD_EVENT_HIDDEN: + LOGI("fgPlatformProcessSingleEvent: VIRTUALKEYBOARD_EVENT_HIDDEN"); + fgPlatformHandleKeyboardHeight(window, 0); + break; + + case VIRTUALKEYBOARD_EVENT_INFO: + LOGI("fgPlatformProcessSingleEvent: VIRTUALKEYBOARD_EVENT_INFO"); + fgPlatformHandleKeyboardHeight(window, virtualkeyboard_event_get_height(fgDisplay.pDisplay.event)); + break; + + default: + LOGW("fgPlatformProcessSingleEvent: unknown virtualkeyboard event: 0x%X", eventType); + break; + } + } +#endif } while(bps_get_event(&fgDisplay.pDisplay.event, 1) == BPS_SUCCESS && fgDisplay.pDisplay.event != NULL); /* Reset event to reduce chances of triggering something */ @@ -518,7 +804,14 @@ void fgPlatformMainLoopPreliminaryWork ( void ) /* Request navigator events */ navigator_request_events(0); - //XXX rotation lock? navigator_rotation_lock(true); + + /* Allow rotation */ + navigator_rotation_lock(false); + +#ifdef __PLAYBOOK__ + /* Request keyboard events */ + virtualkeyboard_request_events(0); +#endif /* Request window events */ screen_request_events(fgDisplay.pDisplay.screenContext); @@ -528,20 +821,27 @@ void fgPlatformMainLoopPostWork ( void ) { LOGI("fgPlatformMainLoopPostWork"); + /* Stop all events */ screen_stop_events(fgDisplay.pDisplay.screenContext); +#ifndef __PLAYBOOK__ navigator_stop_events(0); +#endif } /* deal with work list items */ void fgPlatformInitWork(SFG_Window* window) { - /* notify windowStatus/visibility */ - INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) ); + LOGI("fgPlatformInitWork"); /* Position callback, always at 0,0 */ fghOnPositionNotify(window, 0, 0, GL_TRUE); + /* Get window size */ + int size[2]; + screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size); + fghOnReshapeNotify(window, size[0], size[1], GL_FALSE); + /* Size gets notified on window creation with size detection in mainloop above * XXX CHECK: does this messages happen too early like on windows, * so client code cannot have registered a callback yet and the message