1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-11-17 19:21:04 +00:00

glfw-minecraft: merge glfw-wayland-minecraft into glfw (#310073)

This commit is contained in:
Johannes Jöns 2024-09-02 06:17:29 +00:00 committed by GitHub
commit 80fa723e5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 102 additions and 151 deletions

View file

@ -0,0 +1,59 @@
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

@ -1,13 +1,16 @@
{ stdenv, lib, fetchFromGitHub, cmake
, libGL, libXrandr, libXinerama, libXcursor, libX11, libXi, libXext
, Carbon, Cocoa, Kernel, fixDarwinDylibNames
, darwin, fixDarwinDylibNames
, extra-cmake-modules, wayland
, wayland-scanner, wayland-protocols, libxkbcommon, libdecor
, withMinecraftPatch ? false
}:
stdenv.mkDerivation rec {
let
version = "3.4";
pname = "glfw";
in
stdenv.mkDerivation {
pname = "glfw${lib.optionalString withMinecraftPatch "-minecraft"}";
inherit version;
src = fetchFromGitHub {
owner = "glfw";
@ -17,16 +20,20 @@ stdenv.mkDerivation rec {
};
# Fix linkage issues on X11 (https://github.com/NixOS/nixpkgs/issues/142583)
patches = ./x11.patch;
patches = [
./x11.patch
] ++ lib.optionals withMinecraftPatch [
./0009-Defer-setting-cursor-position-until-the-cursor-is-lo.patch
];
propagatedBuildInputs = [ libGL ];
nativeBuildInputs = [ cmake extra-cmake-modules ]
++ lib.optional stdenv.isDarwin fixDarwinDylibNames
++ lib.optionals stdenv.isDarwin [ fixDarwinDylibNames ]
++ lib.optionals stdenv.isLinux [ wayland-scanner ];
buildInputs =
lib.optionals stdenv.isDarwin [ Carbon Cocoa Kernel ]
lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ Carbon Cocoa Kernel ])
++ lib.optionals stdenv.isLinux [
wayland
wayland-protocols
@ -64,7 +71,7 @@ stdenv.mkDerivation rec {
description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time";
homepage = "https://www.glfw.org/";
license = licenses.zlib;
maintainers = with maintainers; [ marcweber twey ];
maintainers = with maintainers; [ marcweber Scrumplex twey ];
platforms = platforms.unix ++ platforms.windows;
};
}

View file

@ -1,30 +1,33 @@
{
lib,
stdenv,
symlinkJoin,
prismlauncher-unwrapped,
addDriverRunpath,
alsa-lib,
flite,
gamemode,
glfw,
glfw-wayland-minecraft,
mesa-demos,
jdk8,
glfw3-minecraft,
jdk17,
jdk21,
jdk8,
kdePackages,
lib,
libGL,
libX11,
libXcursor,
libXext,
libXrandr,
libXxf86vm,
libjack2,
libpulseaudio,
libusb1,
makeWrapper,
mesa-demos,
openal,
pciutils,
pipewire,
prismlauncher-unwrapped,
stdenv,
symlinkJoin,
udev,
vulkan-loader,
xorg,
xrandr,
additionalLibs ? [ ],
additionalPrograms ? [ ],
@ -37,15 +40,6 @@
],
msaClientID ? null,
textToSpeechSupport ? stdenv.isLinux,
# Adds `glfw-wayland-minecraft` to `LD_LIBRARY_PATH`
# when launched on wayland, allowing for the game to be run natively.
# Make sure to enable "Use system installation of GLFW" in instance settings
# for this to take effect
#
# Warning: This build of glfw may be unstable, and the launcher
# itself can take slightly longer to start
withWaylandGLFW ? false,
}:
assert lib.assertMsg (
@ -56,10 +50,6 @@ assert lib.assertMsg (
textToSpeechSupport -> stdenv.isLinux
) "textToSpeechSupport only has an effect on Linux.";
assert lib.assertMsg (
withWaylandGLFW -> stdenv.isLinux
) "withWaylandGLFW is only available on Linux.";
let
prismlauncher' = prismlauncher-unwrapped.override { inherit msaClientID gamemodeSupport; };
in
@ -69,11 +59,7 @@ symlinkJoin {
paths = [ prismlauncher' ];
nativeBuildInputs =
[ kdePackages.wrapQtAppsHook ]
# purposefully using a shell wrapper here for variable expansion
# see https://github.com/NixOS/nixpkgs/issues/172583
++ lib.optional withWaylandGLFW makeWrapper;
nativeBuildInputs = [ kdePackages.wrapQtAppsHook ];
buildInputs =
[
@ -84,30 +70,17 @@ symlinkJoin {
lib.versionAtLeast kdePackages.qtbase.version "6" && stdenv.isLinux
) kdePackages.qtwayland;
env = {
waylandPreExec = lib.optionalString withWaylandGLFW ''
if [ -n "$WAYLAND_DISPLAY" ]; then
export LD_LIBRARY_PATH=${lib.getLib glfw-wayland-minecraft}/lib:"$LD_LIBRARY_PATH"
fi
'';
};
postBuild =
lib.optionalString withWaylandGLFW ''
qtWrapperArgs+=(--run "$waylandPreExec")
''
+ ''
wrapQtAppsHook
'';
postBuild = ''
wrapQtAppsHook
'';
qtWrapperArgs =
let
runtimeLibs =
[
# lwjgl
stdenv.cc.cc.lib
## native versions
glfw
glfw3-minecraft
openal
## openal
@ -118,11 +91,11 @@ symlinkJoin {
## glfw
libGL
xorg.libX11
xorg.libXext
xorg.libXcursor
xorg.libXrandr
xorg.libXxf86vm
libX11
libXcursor
libXext
libXrandr
libXxf86vm
udev # oshi
@ -136,7 +109,7 @@ symlinkJoin {
runtimePrograms = [
mesa-demos
pciutils # need lspci
xorg.xrandr # needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
xrandr # needed for LWJGL [2.9.2, 3) https://github.com/LWJGL/lwjgl/issues/128
] ++ additionalPrograms;
in

View file

@ -1,64 +0,0 @@
{ stdenv, lib, fetchFromGitHub, fetchpatch2, cmake, extra-cmake-modules
, libGL, wayland, wayland-protocols, libxkbcommon, libdecor
}:
stdenv.mkDerivation {
version = "unstable-2023-06-01";
pname = "glfw-wayland-minecraft";
src = fetchFromGitHub {
owner = "glfw";
repo = "GLFW";
rev = "3eaf1255b29fdf5c2895856c7be7d7185ef2b241";
sha256 = "sha256-UnwuE/3q6I4dS5syagpnqrDEVDK9XSVdyOg7KNkdUUA=";
};
patches = [
(fetchpatch2 {
url = "https://raw.githubusercontent.com/Admicos/minecraft-wayland/15f88a515c63a9716cfdf4090fab8e16543f4ebd/0003-Don-t-crash-on-calls-to-focus-or-icon.patch";
hash = "sha256-NZbKh16h+tWXXnz13QcFBFaeGXMNxZKGQb9xJEahFnE=";
})
(fetchpatch2 {
url = "https://raw.githubusercontent.com/Admicos/minecraft-wayland/15f88a515c63a9716cfdf4090fab8e16543f4ebd/0005-Add-warning-about-being-an-unofficial-patch.patch";
hash = "sha256-QMUNlnlCeFz5gIVdbM+YXPsrmiOl9cMwuVRSOvlw+T0=";
})
];
propagatedBuildInputs = [ libGL ];
nativeBuildInputs = [ cmake extra-cmake-modules ];
buildInputs = [ wayland wayland-protocols libxkbcommon ];
cmakeFlags = [
"-DBUILD_SHARED_LIBS=ON"
"-DGLFW_BUILD_WAYLAND=ON"
"-DGLFW_BUILD_X11=OFF"
"-DCMAKE_C_FLAGS=-D_GLFW_EGL_LIBRARY='\"${lib.getLib libGL}/lib/libEGL.so.1\"'"
];
postPatch = ''
substituteInPlace src/wl_init.c \
--replace "libxkbcommon.so.0" "${lib.getLib libxkbcommon}/lib/libxkbcommon.so.0"
substituteInPlace src/wl_init.c \
--replace "libdecor-0.so.0" "${lib.getLib libdecor}/lib/libdecor-0.so.0"
substituteInPlace src/wl_init.c \
--replace "libwayland-client.so.0" "${lib.getLib wayland}/lib/libwayland-client.so.0"
substituteInPlace src/wl_init.c \
--replace "libwayland-cursor.so.0" "${lib.getLib wayland}/lib/libwayland-cursor.so.0"
substituteInPlace src/wl_init.c \
--replace "libwayland-egl.so.1" "${lib.getLib wayland}/lib/libwayland-egl.so.1"
'';
meta = with lib; {
description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time - with patches to support Minecraft on Wayland";
homepage = "https://www.glfw.org/";
license = licenses.zlib;
maintainers = with maintainers; [ Scrumplex ];
platforms = platforms.linux;
};
}

View file

@ -1,25 +0,0 @@
From 46fb81c69e8acdb70907409f98dd01e387408414 Mon Sep 17 00:00:00 2001
From: Stone Tickle <lattis@mochiro.moe>
Date: Fri, 5 Jun 2020 12:51:25 +0900
Subject: [PATCH] set O_NONBLOCK on repeat timerfd
---
src/wl_init.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/wl_init.c b/src/wl_init.c
index 49e7cc52..43569bef 100644
--- a/src/wl_init.c
+++ b/src/wl_init.c
@@ -1166,7 +1166,7 @@ int _glfwPlatformInit(void)
_glfw.wl.timerfd = -1;
if (_glfw.wl.seatVersion >= 4)
- _glfw.wl.timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC);
+ _glfw.wl.timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK);
if (_glfw.wl.pointer && _glfw.wl.shm)
{
--
2.31.1

View file

@ -529,6 +529,7 @@ mapAliases ({
glew-egl = lib.warn "'glew-egl' is now provided by 'glew' directly" glew; # Added 2024-08-11
glide = throw "'glide' has been removed as it is unmaintained, please use Go modules instead"; # Added 2023-12-26
glfw-wayland = glfw; # Added 2024-04-19
glfw-wayland-minecraft = glfw3-minecraft; # Added 2024-05-08
glxinfo = mesa-demos; # Added 2024-07-04
gmailieer = lieer; # Added 2020-04-19
gmic-qt-krita = throw "gmic-qt-krita was removed as it's no longer supported upstream."; # Converted to throw 2023-02-02

View file

@ -20255,10 +20255,10 @@ with pkgs;
inherit (darwin.apple_sdk.frameworks) AGL OpenGL;
};
glfw = glfw3;
glfw-wayland-minecraft = callPackage ../development/libraries/glfw/3.x-wayland-minecraft.nix {};
glfw2 = callPackage ../development/libraries/glfw/2.x.nix { };
glfw3 = callPackage ../development/libraries/glfw/3.x.nix {
inherit (darwin.apple_sdk.frameworks) Carbon Cocoa Kernel;
glfw3-minecraft = callPackage ../by-name/gl/glfw3/package.nix {
withMinecraftPatch = true;
};
glibc = callPackage ../development/libraries/glibc {