From 0fd562af40e36b6866fa64cc1f007b829f2d1126 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sun, 6 Mar 2022 20:07:49 -0500 Subject: [PATCH] Allow Disabling Raw Mouse Motion --- .../available-feature-flags | 1 + media-layer/core/src/media.c | 18 ++++++++++++++++-- media-layer/include/media-layer/core.h | 1 + media-layer/proxy/src/media-layer-core.c | 17 +++++++++++++++++ media-layer/stubs/CMakeLists.txt | 2 +- mods/src/input/input.cpp | 6 ++++++ 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/launcher/client-data/lib/minecraft-pi-reborn-client/available-feature-flags b/launcher/client-data/lib/minecraft-pi-reborn-client/available-feature-flags index 5a41c92..c8b5788 100644 --- a/launcher/client-data/lib/minecraft-pi-reborn-client/available-feature-flags +++ b/launcher/client-data/lib/minecraft-pi-reborn-client/available-feature-flags @@ -29,3 +29,4 @@ TRUE External Server Support TRUE Load Language Files TRUE Implement Sound Engine TRUE Close Current Screen On Death +FALSE Disable Raw Mouse Motion (Not Recommended) diff --git a/media-layer/core/src/media.c b/media-layer/core/src/media.c index 1dd3510..01c9f34 100644 --- a/media-layer/core/src/media.c +++ b/media-layer/core/src/media.c @@ -27,7 +27,7 @@ void media_set_interactable(int toggle) { // GLFW Code Not Needed In Headless Mode #ifndef MCPI_HEADLESS_MODE -static GLFWwindow *glfw_window; +static GLFWwindow *glfw_window = NULL; // Handle GLFW Error static void glfw_error(__attribute__((unused)) int error, const char *description) { @@ -227,6 +227,20 @@ static void glfw_scroll(__attribute__((unused)) GLFWwindow *window, __attribute_ // Track Media Layer State static int is_running = 0; +// Track If Raw Mouse Motion Is Enabled +static int raw_mouse_motion_enabled = 1; +void media_set_raw_mouse_motion_enabled(int enabled) { + raw_mouse_motion_enabled = enabled; +#ifndef MCPI_HEADLESS_MODE + if (is_running) { + glfwSetInputMode(glfw_window, GLFW_RAW_MOUSE_MOTION, GLFW_FALSE); + } +#endif // #ifndef MCPI_HEADLESS_MODE + if (!raw_mouse_motion_enabled) { + WARN("%s", "Raw mouse motion has been DISABLED, this IS NOT recommended, and should only ever be used on systems that don't support or have broken raw mouse motion."); + } +} + // Disable V-Sync static int disable_vsync = 0; void media_disable_vsync() { @@ -409,7 +423,7 @@ static void update_cursor() { glfwSetInputMode(glfw_window, GLFW_CURSOR, new_mode); // Handle Cursor Lock/Unlock - if ((new_mode == GLFW_CURSOR_DISABLED && old_mode != GLFW_CURSOR_DISABLED) || (new_mode != GLFW_CURSOR_DISABLED && old_mode == GLFW_CURSOR_DISABLED)) { + if (raw_mouse_motion_enabled && ((new_mode == GLFW_CURSOR_DISABLED && old_mode != GLFW_CURSOR_DISABLED) || (new_mode != GLFW_CURSOR_DISABLED && old_mode == GLFW_CURSOR_DISABLED))) { // Use Raw Mouse Motion glfwSetInputMode(glfw_window, GLFW_RAW_MOUSE_MOTION, new_mode == GLFW_CURSOR_DISABLED ? GLFW_TRUE : GLFW_FALSE); } diff --git a/media-layer/include/media-layer/core.h b/media-layer/include/media-layer/core.h index 1eddc5e..5893361 100644 --- a/media-layer/include/media-layer/core.h +++ b/media-layer/include/media-layer/core.h @@ -17,6 +17,7 @@ void media_cleanup(); void media_get_framebuffer_size(int *width, int *height); void media_set_interactable(int is_interactable); void media_disable_vsync(); +void media_set_raw_mouse_motion_enabled(int enabled); #ifdef __cplusplus } diff --git a/media-layer/proxy/src/media-layer-core.c b/media-layer/proxy/src/media-layer-core.c index b01d356..b6458c6 100644 --- a/media-layer/proxy/src/media-layer-core.c +++ b/media-layer/proxy/src/media-layer-core.c @@ -336,3 +336,20 @@ CALL(63, media_disable_vsync, void, ()) { media_disable_vsync(); #endif } + +CALL(64, media_set_raw_mouse_motion_enabled, void, (int enabled)) { +#if defined(MEDIA_LAYER_PROXY_SERVER) + // Lock Proxy + start_proxy_call(); + + // Arguments + write_int(enabled); + + // Release Proxy + end_proxy_call(); +#else + int enabled = read_int(); + // Run + media_set_raw_mouse_motion_enabled(enabled); +#endif +} diff --git a/media-layer/stubs/CMakeLists.txt b/media-layer/stubs/CMakeLists.txt index 656dff8..fda90d5 100644 --- a/media-layer/stubs/CMakeLists.txt +++ b/media-layer/stubs/CMakeLists.txt @@ -34,7 +34,7 @@ if(BUILD_ARM_COMPONENTS) # MCPI Depends On GLESv2, But Uses GLESv1_CM install_symlink("libGLESv1_CM.so.1" "${MCPI_LIB_DIR}/libGLESv2.so") - # Prevent MCPI From Linking To The Legacy GL Driver When Directly Linking To GL + # Prevent MCPI From Linking To The Legacy GL Driver When Directly Linking To GL (RPI-Specific) if(NOT MCPI_HEADLESS_MODE AND NOT MCPI_USE_MEDIA_LAYER_PROXY) # Symlinks install_symlink("/usr/lib/arm-linux-gnueabihf/libEGL.so.1" "${MCPI_LIB_DIR}/libEGL.so") diff --git a/mods/src/input/input.cpp b/mods/src/input/input.cpp index 7e2e697..0729a24 100644 --- a/mods/src/input/input.cpp +++ b/mods/src/input/input.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "../feature/feature.h" #include "../init/init.h" @@ -46,4 +47,9 @@ void init_input() { // Allow Attacking Mobs _init_attack(); + + // Disable Raw Mouse Motion + if (feature_has("Disable Raw Mouse Motion (Not Recommended)", 9)) { + media_set_raw_mouse_motion_enabled(0); + } }