glfw3-minecraft: add Wayland patches (#444090)

This commit is contained in:
Sefa Eyeoglu
2025-10-18 20:26:09 +00:00
committed by GitHub
2 changed files with 10 additions and 65 deletions

View File

@@ -1,59 +0,0 @@
From 9997ae55a47de469ea26f8437c30b51483abda5f Mon Sep 17 00:00:00 2001
From: Dan Klishch <danilklishch@gmail.com>
Date: Sat, 30 Sep 2023 23:38:05 -0400
Subject: Defer setting cursor position until the cursor is locked
---
src/wl_platform.h | 3 +++
src/wl_window.c | 14 ++++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/wl_platform.h b/src/wl_platform.h
index ca34f66e..cd1f227f 100644
--- a/src/wl_platform.h
+++ b/src/wl_platform.h
@@ -403,6 +403,9 @@ typedef struct _GLFWwindowWayland
int scaleSize;
int compositorPreferredScale;
+ double askedCursorPosX, askedCursorPosY;
+ GLFWbool didAskForSetCursorPos;
+
struct zwp_relative_pointer_v1* relativePointer;
struct zwp_locked_pointer_v1* lockedPointer;
struct zwp_confined_pointer_v1* confinedPointer;
diff --git a/src/wl_window.c b/src/wl_window.c
index 1de26558..0df16747 100644
--- a/src/wl_window.c
+++ b/src/wl_window.c
@@ -2586,8 +2586,9 @@ 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;
}
void _glfwSetCursorModeWayland(_GLFWwindow* window, int mode)
@@ -2819,6 +2820,15 @@ 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;
+ 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));
+ }
}
static void lockedPointerHandleUnlocked(void* userData,
--
2.42.0

View File

@@ -23,6 +23,12 @@
}:
let
version = "3.4";
minecraftPatches = fetchFromGitHub {
owner = "BoyOrigin";
repo = "glfw-wayland";
rev = "f62b4ae8f93149fd754cadecd51d8b1a07d20522";
hash = "sha256-kvWP34rOD4HSTvnKb33nvVquTGZoqP8/l+8XQ0h3b7Y=";
};
in
stdenv.mkDerivation {
pname = "glfw${lib.optionalString withMinecraftPatch "-minecraft"}";
@@ -36,12 +42,10 @@ stdenv.mkDerivation {
};
# Fix linkage issues on X11 (https://github.com/NixOS/nixpkgs/issues/142583)
patches = [
./x11.patch
]
++ lib.optionals withMinecraftPatch [
./0009-Defer-setting-cursor-position-until-the-cursor-is-lo.patch
];
patches = [ ./x11.patch ];
prePatch = lib.optionalString withMinecraftPatch ''
patches+=(${minecraftPatches}/patches/*.patch)
'';
propagatedBuildInputs = lib.optionals (!stdenv.hostPlatform.isWindows) [ libGL ];