Set GLFW window attrib; Proper external mouse lock

Setting window attribute fixes DynamicFPS mod being broken
This commit is contained in:
Duy Tran Khanh committed 2022-03-17 07:24:41 +07:00
1 parent a6c9648345
commit 580da57855
6 files changed
+52 -6

No files matched your search

@@ -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;
+17 -1
View File
@@ -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
+5
View File
@@ -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<UIOpenURLContext *> *)URLContexts
+5 -4
View File
@@ -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);
+17
View File
@@ -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
);
}
+4
View File
@@ -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);