diff --git a/README.md b/README.md index d16fb8dd..a32c395d 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ information on what to include when reporting a bug. - [Null] Added EGL context creation on Mesa via `EGL_MESA_platform_surfaceless` - [EGL] Allowed native access on Wayland with `GLFW_CONTEXT_CREATION_API` set to `GLFW_NATIVE_CONTEXT_API` (#2518) - - [Cocoa] Added `glfwSetTrackpadZoomCallback` and `glfwSetTrackpadRotateCallback` + - [Cocoa & Wayland] Added `glfwSetTrackpadZoomCallback` and `glfwSetTrackpadRotateCallback` for trackpad zoom and rotate events (#90) diff --git a/docs/input.md b/docs/input.md index 3ef1aebe..2bfa9c7d 100644 --- a/docs/input.md +++ b/docs/input.md @@ -581,6 +581,42 @@ void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) A normal mouse wheel, being vertical, provides offsets along the Y-axis. +### Trackpad zoom and rotate {#input_mouse_trackpad_gestures} + +Trackpad events are currently only available on macOS and Wayland (Linux). + +If you wish to be notified when a zoom gesture is performed on a trackpad, +set the trackpadZoom callback. + +```c +glfwSetTrackpadZoomCallback(window, trackpad_zoom_callback); +``` + +The callback function receives the scale of the zoom, which is a ratio that +should be multiplied by the current zoom level to get the new zoom level. + +```c +static void trackpad_zoom_callback(GLFWwindow* window, double scale) +{ + my_app->zoom_level *= scale; +} +``` + +For trackpad rotate gestures, set the trackpadRotateCallback. + +```c +glfwSetTrackpadRotateCallback(window, trackpad_rotate_callback); +``` + +The callback function recieves the angle, in degrees, to rotate by. + +```c +static void trackpad_rotate_callback(GLFWwindow* window, double angle) +{ + my_app->rotation_angle_degrees += angle; +} +``` + ## Joystick input {#joystick} diff --git a/include/GLFW/glfw3.h b/include/GLFW/glfw3.h index 4152b648..48579930 100644 --- a/include/GLFW/glfw3.h +++ b/include/GLFW/glfw3.h @@ -1880,7 +1880,8 @@ typedef void (* GLFWscrollfun)(GLFWwindow* window, double xoffset, double yoffse * @endcode * * @param[in] window The window that received the event. - * @param[in] scale The manigification amount, as a scale factor + * @param[in] scale The manigification amount, to be multiplied by the current + * scale factor to get the new scale factor. * * @sa @ref glfwSetTrackpadZoomCallback * diff --git a/src/input.c b/src/input.c index 4aa44e3d..17c66b64 100644 --- a/src/input.c +++ b/src/input.c @@ -1069,7 +1069,7 @@ GLFWAPI GLFWtrackpadzoomfun glfwSetTrackpadZoomCallback(GLFWwindow* handle, return cbfun; } -GLFWAPI GLFWtrackpadzoomfun glfwSetTrackpadRotateCallback(GLFWwindow* handle, +GLFWAPI GLFWtrackpadrotatefun glfwSetTrackpadRotateCallback(GLFWwindow* handle, GLFWtrackpadrotatefun cbfun) { _GLFWwindow* window = (_GLFWwindow*) handle;