Skip to content

Commit

Permalink
Upstream & Much more accurate glfwSetCursorPos & Avoid error on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
BoyOrigin committed Mar 7, 2024
1 parent 5a16155 commit f62b4ae
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
2 changes: 1 addition & 1 deletion glfw
Submodule glfw updated 72 files
+2 −2 .gitignore
+1 −1 CMakeLists.txt
+5 −324 README.md
+1 −1 docs/build.md
+1 −1 docs/extra.css
+1 −1 docs/extra.css.map
+4 −0 docs/extra.scss
+3 −3 docs/intro.md
+1 −4 docs/main.md
+10 −315 docs/news.md
+2 −2 include/GLFW/glfw3.h
+1 −1 include/GLFW/glfw3native.h
+1 −1 src/cocoa_init.m
+1 −1 src/cocoa_joystick.h
+1 −1 src/cocoa_joystick.m
+1 −1 src/cocoa_monitor.m
+1 −1 src/cocoa_platform.h
+1 −1 src/cocoa_time.c
+1 −1 src/cocoa_time.h
+1 −1 src/cocoa_window.m
+1 −1 src/context.c
+1 −1 src/egl_context.c
+1 −1 src/glx_context.c
+1 −1 src/init.c
+1 −1 src/input.c
+1 −1 src/internal.h
+1 −1 src/linux_joystick.c
+1 −1 src/linux_joystick.h
+1 −1 src/mappings.h
+1 −1 src/mappings.h.in
+1 −1 src/monitor.c
+1 −1 src/nsgl_context.m
+1 −1 src/null_init.c
+1 −1 src/null_joystick.c
+1 −1 src/null_joystick.h
+1 −1 src/null_monitor.c
+1 −1 src/null_platform.h
+1 −1 src/null_window.c
+1 −1 src/osmesa_context.c
+1 −1 src/platform.c
+1 −1 src/platform.h
+1 −1 src/posix_module.c
+1 −1 src/posix_poll.c
+1 −1 src/posix_poll.h
+1 −1 src/posix_thread.c
+1 −1 src/posix_thread.h
+1 −1 src/posix_time.c
+1 −1 src/posix_time.h
+1 −1 src/vulkan.c
+1 −1 src/wgl_context.c
+1 −1 src/win32_init.c
+1 −1 src/win32_joystick.c
+1 −1 src/win32_joystick.h
+1 −1 src/win32_module.c
+1 −1 src/win32_monitor.c
+1 −1 src/win32_platform.h
+1 −1 src/win32_thread.c
+1 −1 src/win32_thread.h
+1 −1 src/win32_time.c
+1 −1 src/win32_time.h
+1 −1 src/win32_window.c
+1 −1 src/window.c
+1 −1 src/wl_init.c
+1 −1 src/wl_monitor.c
+1 −1 src/wl_platform.h
+1 −1 src/wl_window.c
+1 −1 src/x11_init.c
+1 −1 src/x11_monitor.c
+1 −1 src/x11_platform.h
+1 −1 src/x11_window.c
+1 −1 src/xkb_unicode.c
+1 −1 src/xkb_unicode.h
30 changes: 20 additions & 10 deletions patches/0003-Implement-glfwSetCursorPosWayland.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
From 70bcc32a8e60c012e91f74bab9062c1a6596b39a Mon Sep 17 00:00:00 2001
From a5f94d704dd418d6e39cc4f2fe6d6b569dce39f1 Mon Sep 17 00:00:00 2001
From: FayBoy <ahmadyasinfikri@gmail.com>
Date: Thu, 22 Feb 2024 19:30:53 +0700
Subject: [PATCH] Implement glfwSetCursorPosWayland


diff --git a/src/wl_platform.h b/src/wl_platform.h
index b17fa722..7ffc7e83 100644
index 83cb12a5..d51c2134 100644
--- a/src/wl_platform.h
+++ b/src/wl_platform.h
@@ -415,6 +415,8 @@ typedef struct _GLFWwindowWayland
Expand All @@ -18,37 +18,47 @@ index b17fa722..7ffc7e83 100644

// Wayland-specific global data
diff --git a/src/wl_window.c b/src/wl_window.c
index aab79d01..b1b280a7 100644
index aa4e419a..ae9a6728 100644
--- a/src/wl_window.c
+++ b/src/wl_window.c
@@ -2674,8 +2674,9 @@ void _glfwGetCursorPosWayland(_GLFWwindow* window, double* xpos, double* ypos)
@@ -2674,8 +2674,17 @@ void _glfwGetCursorPosWayland(_GLFWwindow* window, double* xpos, double* ypos)

void _glfwSetCursorPosWayland(_GLFWwindow* window, double x, double y)
{
- _glfwInputError(GLFW_FEATURE_UNAVAILABLE,
- "Wayland: The platform does not support setting the cursor position");
+ window->wl.didAskForSetCursorPos = true;
+ window->wl.askedCursorPosX = x;
+ window->wl.askedCursorPosY = y;
+ if (window->wl.lockedPointer) {
+ zwp_locked_pointer_v1_set_cursor_position_hint(window->wl.lockedPointer,
+ wl_fixed_from_double(x),
+ wl_fixed_from_double(y));
+ window->wl.cursorPosX = x;
+ window->wl.cursorPosY = y;
+ } else {
+ window->wl.didAskForSetCursorPos = GLFW_TRUE;
+ window->wl.askedCursorPosX = x;
+ window->wl.askedCursorPosY = y;
+ }
}

void _glfwSetCursorModeWayland(_GLFWwindow* window, int mode)
@@ -2909,6 +2910,15 @@ static const struct zwp_relative_pointer_v1_listener relativePointerListener =
@@ -2909,6 +2918,17 @@ static const struct zwp_relative_pointer_v1_listener relativePointerListener =
static void lockedPointerHandleLocked(void* userData,
struct zwp_locked_pointer_v1* lockedPointer)
{
+ _GLFWwindow* window = userData;
+
+ if (window->wl.didAskForSetCursorPos)
+ {
+ window->wl.didAskForSetCursorPos = false;
+ window->wl.didAskForSetCursorPos = GLFW_FALSE;
+ zwp_locked_pointer_v1_set_cursor_position_hint(window->wl.lockedPointer,
+ wl_fixed_from_double(window->wl.askedCursorPosX),
+ wl_fixed_from_double(window->wl.askedCursorPosY));
+ window->wl.cursorPosX = window->wl.askedCursorPosX;
+ window->wl.cursorPosY = window->wl.askedCursorPosY;
+ }
}

static void lockedPointerHandleUnlocked(void* userData,
--
2.43.0
2.44.0

25 changes: 25 additions & 0 deletions patches/0005-Avoid-error-on-startup.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 5761eccda29777719d919eb0462a6f7d3cc32b36 Mon Sep 17 00:00:00 2001
From: FayBoy <ahmadyasinfikri@gmail.com>
Date: Thu, 7 Mar 2024 03:05:59 +0700
Subject: [PATCH] Avoid error on startup

This is an exclusive fix for older version of Minecraft that is using LWJGL3.

diff --git a/src/wl_window.c b/src/wl_window.c
index 58382a48..c0a31237 100644
--- a/src/wl_window.c
+++ b/src/wl_window.c
@@ -2234,8 +2234,8 @@ void _glfwSetWindowTitleWayland(_GLFWwindow* window, const char* title)
void _glfwSetWindowIconWayland(_GLFWwindow* window,
int count, const GLFWimage* images)
{
- _glfwInputError(GLFW_FEATURE_UNAVAILABLE,
- "Wayland: The platform does not support setting the window icon");
+ fprintf(stderr,
+ "[GLFW] Wayland: The platform does not support setting the window icon\n");
}

void _glfwGetWindowPosWayland(_GLFWwindow* window, int* xpos, int* ypos)
--
2.44.0

0 comments on commit f62b4ae

Please sign in to comment.