diff --git a/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java b/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java index 1b735772..01191915 100644 --- a/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java +++ b/JavaApp/src/main/java/org/lwjgl/glfw/GLFW.java @@ -873,7 +873,7 @@ public class GLFW } public static int glfwGetWindowAttrib(@NativeType("GLFWwindow *") long window, int attrib) { - return internalGetWindow(window).windowAttribs.get(attrib); + return internalGetWindow(window).windowAttribs.getOrDefault(attrib, 0); } public static void glfwSetWindowAttrib(@NativeType("GLFWwindow *") long window, int attrib, int value) { @@ -977,6 +977,9 @@ public class GLFW win.title = title; + win.windowAttribs.put(GLFW_HOVERED, 1); + win.windowAttribs.put(GLFW_VISIBLE, 1); + mGLFWWindowMap.put(ptr, win); mainContext = ptr; return ptr; diff --git a/Natives/AppDelegate.m b/Natives/AppDelegate.m index 5d4e26b9..90a4b183 100644 --- a/Natives/AppDelegate.m +++ b/Natives/AppDelegate.m @@ -2,12 +2,12 @@ #import "LoginViewController.h" #import "SceneDelegate.h" #import "ios_uikit_bridge.h" +#include "utils.h" @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { if (@available(iOS 13.0, *)) { - } else { self.window = ([[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]); launchInitialViewController(self.window); @@ -39,4 +39,20 @@ return YES; } +- (void)applicationDidBecomeActive:(UIApplication *)application { + CallbackBridge_setWindowAttrib(GLFW_FOCUSED, 1); +} + +- (void)applicationDidEnterBackground:(UIApplication *)application { + CallbackBridge_setWindowAttrib(GLFW_VISIBLE, 0); +} + +- (void)applicationWillEnterForeground:(UIApplication *)application { + CallbackBridge_setWindowAttrib(GLFW_VISIBLE, 1); +} + +- (void)applicationWillResignActive:(UIApplication *)application { + CallbackBridge_setWindowAttrib(GLFW_FOCUSED, 0); +} + @end diff --git a/Natives/SceneDelegate.m b/Natives/SceneDelegate.m index d3f02c10..6c9e0bd3 100644 --- a/Natives/SceneDelegate.m +++ b/Natives/SceneDelegate.m @@ -1,6 +1,7 @@ #import "SceneDelegate.h" #import "LoginViewController.h" #import "ios_uikit_bridge.h" +#include "utils.h" @interface SceneDelegate () @@ -34,18 +35,21 @@ - (void)sceneDidBecomeActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){ // Called when the scene has moved from an inactive state to an active state. // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. + CallbackBridge_setWindowAttrib(GLFW_FOCUSED, 1); } - (void)sceneWillResignActive:(UIScene *)scene API_AVAILABLE(ios(13.0)){ // Called when the scene will move from an active state to an inactive state. // This may occur due to temporary interruptions (ex. an incoming phone call). + CallbackBridge_setWindowAttrib(GLFW_FOCUSED, 0); } - (void)sceneWillEnterForeground:(UIScene *)scene API_AVAILABLE(ios(13.0)){ // Called as the scene transitions from the background to the foreground. // Use this method to undo the changes made on entering the background. + CallbackBridge_setWindowAttrib(GLFW_VISIBLE, 1); } @@ -53,6 +57,7 @@ // Called as the scene transitions from the foreground to the background. // Use this method to save data, release shared resources, and store enough scene-specific state information // to restore the scene back to its current state. + CallbackBridge_setWindowAttrib(GLFW_VISIBLE, 0); } - (void)scene:(UIScene *)scene openURLContexts:(nonnull NSSet *)URLContexts diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index 1db992bb..3d392845 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -458,13 +458,11 @@ const void * _CGDataProviderGetBytePointerCallbackOSMESA(void *info) { - (void)registerMouseCallbacks:(GCMouse *)mouse API_AVAILABLE(ios(14.0)) { NSLog(@"Input: Got mouse %@", mouse); -/* mouse.mouseInput.mouseMovedHandler = ^(GCMouseInput * _Nonnull mouse, float deltaX, float deltaY) { if (!isGrabbing) return; - x += deltaX / 2.5; - y += -deltaY / 2.5; + [self sendTouchPoint:CGPointMake(deltaX / 2.5, -deltaY / 2.5) withEvent:ACTION_MOVE_MOTION]; }; -*/ + mouse.mouseInput.leftButton.pressedChangedHandler = ^(GCControllerButtonInput * _Nonnull button, float value, BOOL pressed) { CallbackBridge_nativeSendMouseButton(GLFW_MOUSE_BUTTON_LEFT, pressed, 0); }; @@ -516,6 +514,9 @@ const void * _CGDataProviderGetBytePointerCallbackOSMESA(void *info) { - (void)surfaceOnHover:(UIHoverGestureRecognizer *)sender API_AVAILABLE(ios(13.0)) { if (@available(iOS 13.0, *)) { + if (isGrabbing && @available(iOS 14.0, *)) { + return; + } CGPoint point = [sender locationInView:self.view]; // NSLog(@"Mouse move!!"); // NSLog(@"Mouse pos = %f, %f", point.x, point.y); diff --git a/Natives/input_bridge_v3.m b/Natives/input_bridge_v3.m index 8fb57a6d..245ca47f 100644 --- a/Natives/input_bridge_v3.m +++ b/Natives/input_bridge_v3.m @@ -450,3 +450,20 @@ void CallbackBridge_sendKeycode(int keycode, jchar keychar, int scancode, int mo CallbackBridge_nativeSendChar(keychar); } } + +void CallbackBridge_setWindowAttrib(int attrib, int value) { + if (!showingWindow || !isInputReady) { + return; // nothing to do yet + } + + jclass glfwClazz = (*runtimeJNIEnvPtr_JRE)->FindClass(runtimeJNIEnvPtr_JRE, "org/lwjgl/glfw/GLFW"); + assert(glfwClazz != NULL); + jmethodID glfwMethod = (*runtimeJNIEnvPtr_JRE)->GetStaticMethodID(runtimeJNIEnvPtr_JRE, glfwClazz, "glfwSetWindowAttrib", "(JII)V"); + assert(glfwMethod != NULL); + + (*runtimeJNIEnvPtr_JRE)->CallStaticVoidMethod( + runtimeJNIEnvPtr_JRE, + glfwClazz, glfwMethod, + (jlong) showingWindow, attrib, value + ); +} diff --git a/Natives/utils.h b/Natives/utils.h index 5d4db85d..bc65e435 100644 --- a/Natives/utils.h +++ b/Natives/utils.h @@ -24,6 +24,9 @@ #define EVENT_TYPE_WINDOW_POS 1008 #define EVENT_TYPE_WINDOW_SIZE 1009 +#define GLFW_FOCUSED 0x00020001 +#define GLFW_VISIBLE 0x00020004 + #define SPECIALBTN_KEYBOARD -1 #define SPECIALBTN_TOGGLECTRL -2 #define SPECIALBTN_MOUSEPRI -3 @@ -90,3 +93,4 @@ void CallbackBridge_nativeSendScreenSize(int width, int height); void CallbackBridge_nativeSendScroll(CGFloat xoffset, CGFloat yoffset); void CallbackBridge_nativeSendWindowPos(jint x, jint y); void CallbackBridge_sendKeycode(int keycode, jchar keychar, int scancode, int modifiers, BOOL isDown); +void CallbackBridge_setWindowAttrib(int attrib, int value);