Compare commits

...

7 Commits

Author SHA1 Message Date
Pannoniae
dd5db27aa1
Merge a284523f9e into dbadda2683 2025-12-11 13:47:35 -03:00
Camilla Löwy
dbadda2683 Formatting 2025-12-05 13:33:10 +01:00
Camilla Löwy
08449b7183 Linux: Add missing header for ioctl
Fixes #2778
2025-12-04 20:30:12 +01:00
Camilla Löwy
1ce855b0b1 Wayland: Fix missing checks for optional protocol 2025-12-04 20:30:12 +01:00
Camilla Löwy
ebff6606ee Simplify test for shared library build 2025-11-17 22:57:23 +01:00
Pannoniae
a284523f9e fix MinGW build 2025-08-09 14:45:08 +01:00
Pannoniae
8ef7bfdd2e clean application of the patch for #2684 2025-07-30 19:07:18 +01:00
11 changed files with 261 additions and 90 deletions

View File

@ -38,11 +38,7 @@ set(GLFW_LIBRARY_TYPE "${GLFW_LIBRARY_TYPE}" CACHE STRING
"Library type override for GLFW (SHARED, STATIC, OBJECT, or empty to follow BUILD_SHARED_LIBS)")
if (GLFW_LIBRARY_TYPE)
if (GLFW_LIBRARY_TYPE STREQUAL "SHARED")
set(GLFW_BUILD_SHARED_LIBRARY TRUE)
else()
set(GLFW_BUILD_SHARED_LIBRARY FALSE)
endif()
string(COMPARE EQUAL "${GLFW_LIBRARY_TYPE}" "SHARED" GLFW_BUILD_SHARED_LIBRARY)
else()
set(GLFW_BUILD_SHARED_LIBRARY ${BUILD_SHARED_LIBS})
endif()

View File

@ -162,6 +162,7 @@ video tutorials.
- Marcel Metz
- Liam Middlebrook
- mightgoyardstill
- Mihail
- Ave Milia
- Icyllis Milica
- Jonathan Miller

View File

@ -146,11 +146,14 @@ information on what to include when reporting a bug.
from a modal to the content area
- [Wayland] Bugfix: free modules at end of terminate function to resolve
potential segmentation fault (#2744)
- [Wayland] Bugfix: Confining or disabling the cursor could segfault on
compositors without `pointer-constraints-unstable-v1`
- [X11] Bugfix: Running without a WM could trigger an assert (#2593,#2601,#2631)
- [X11] Bugfix: Occasional crash when an idle display awakes (#2766)
- [X11] Bugfix: Prevent BadWindow when creating small windows with a content scale
less than 1 (#2754)
- [X11] Bugfix: Clamp width and height to >= 1 to prevent BadValue error and app exit
- [Linux] Bugfix: The header for `ioctl` was only implicitly included (#2778)
- [Null] Added Vulkan 'window' surface creation via `VK_EXT_headless_surface`
- [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

View File

@ -32,6 +32,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/inotify.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>

View File

@ -528,7 +528,8 @@ void _glfwUpdateKeyNamesWin32(void)
if (key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_ADD)
{
const UINT vks[] = {
const UINT vks[] =
{
VK_NUMPAD0, VK_NUMPAD1, VK_NUMPAD2, VK_NUMPAD3,
VK_NUMPAD4, VK_NUMPAD5, VK_NUMPAD6, VK_NUMPAD7,
VK_NUMPAD8, VK_NUMPAD9, VK_DECIMAL, VK_DIVIDE,

View File

@ -35,6 +35,19 @@
#include <assert.h>
#include <windowsx.h>
#include <shellapi.h>
#include <BaseTsd.h>
#include <stdio.h>
#ifdef _WIN64
typedef UINT64 QWORD; // Needed for NEXTRAWINPUTBLOCK()
#endif
#ifndef RI_MOUSE_HWHEEL
// MinGW may not have the define for RI_MOUSE_HWHEEL
#define RI_MOUSE_HWHEEL 0x0800
#endif
// Returns the window style for the specified window
//
@ -265,7 +278,7 @@ static void releaseCursor(void)
//
static void enableRawMouseMotion(_GLFWwindow* window)
{
const RAWINPUTDEVICE rid = { 0x01, 0x02, 0, window->win32.handle };
const RAWINPUTDEVICE rid = { 0x01, 0x02, RIDEV_NOLEGACY, window->win32.handle };
if (!RegisterRawInputDevices(&rid, 1, sizeof(rid)))
{
@ -894,77 +907,6 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM l
return 0;
}
case WM_INPUT:
{
UINT size = 0;
HRAWINPUT ri = (HRAWINPUT) lParam;
RAWINPUT* data = NULL;
int dx, dy;
if (_glfw.win32.disabledCursorWindow != window)
break;
if (!window->rawMouseMotion)
break;
GetRawInputData(ri, RID_INPUT, NULL, &size, sizeof(RAWINPUTHEADER));
if (size > (UINT) _glfw.win32.rawInputSize)
{
_glfw_free(_glfw.win32.rawInput);
_glfw.win32.rawInput = _glfw_calloc(size, 1);
_glfw.win32.rawInputSize = size;
}
size = _glfw.win32.rawInputSize;
if (GetRawInputData(ri, RID_INPUT,
_glfw.win32.rawInput, &size,
sizeof(RAWINPUTHEADER)) == (UINT) -1)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to retrieve raw input data");
break;
}
data = _glfw.win32.rawInput;
if (data->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE)
{
POINT pos = {0};
int width, height;
if (data->data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP)
{
pos.x += GetSystemMetrics(SM_XVIRTUALSCREEN);
pos.y += GetSystemMetrics(SM_YVIRTUALSCREEN);
width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
}
else
{
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);
}
pos.x += (int) ((data->data.mouse.lLastX / 65535.f) * width);
pos.y += (int) ((data->data.mouse.lLastY / 65535.f) * height);
ScreenToClient(window->win32.handle, &pos);
dx = pos.x - window->win32.lastCursorPosX;
dy = pos.y - window->win32.lastCursorPosY;
}
else
{
dx = data->data.mouse.lLastX;
dy = data->data.mouse.lLastY;
}
_glfwInputCursorPos(window,
window->virtualCursorPosX + dx,
window->virtualCursorPosY + dy);
window->win32.lastCursorPosX += dx;
window->win32.lastCursorPosY += dy;
break;
}
case WM_MOUSELEAVE:
{
window->win32.cursorTracked = GLFW_FALSE;
@ -2086,11 +2028,215 @@ GLFWbool _glfwRawMouseMotionSupportedWin32(void)
return GLFW_TRUE;
}
void _processRawInput(void)
{
UINT size = 0;
UINT riSize = 0;
_GLFWwindow* window = _glfw.windowListHead;
if (_glfw.win32.disabledCursorWindow != window)
return;
if (!window->rawMouseMotion)
return;
// get the size of the raw input buffer
UINT result = GetRawInputBuffer(NULL, &riSize, sizeof(RAWINPUTHEADER));
if (result == (UINT)-1)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to retrieve raw input buffer size");
return;
}
UINT byteCount = riSize * 16;
if (byteCount > (UINT)_glfw.win32.rawInputSize)
{
_glfw_free(_glfw.win32.rawInput);
_glfw.win32.rawInput = _glfw_calloc(byteCount, 1);
_glfw.win32.rawInputSize = byteCount;
}
// read it (actually) this time into the buffer
size = _glfw.win32.rawInputSize;
result = GetRawInputBuffer(_glfw.win32.rawInput, &size, sizeof(RAWINPUTHEADER));
if (result == (UINT)-1)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
"Win32: Failed to retrieve raw input buffer");
_glfw_free(_glfw.win32.rawInput);
return;
}
// print msg count
//printf("raw input count: %u\n", result);
UINT riCount = result;
RAWINPUT* data = _glfw.win32.rawInput;
for (unsigned int i = 0; i < riCount; ++i)
{
if (data->header.dwType == RIM_TYPEMOUSE) {
int dx = 0, dy = 0;
if (data->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE)
{
POINT pos = {0};
int width, height;
if (data->data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP)
{
pos.x += GetSystemMetrics(SM_XVIRTUALSCREEN);
pos.y += GetSystemMetrics(SM_YVIRTUALSCREEN);
width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
}
else
{
width = GetSystemMetrics(SM_CXSCREEN);
height = GetSystemMetrics(SM_CYSCREEN);
}
pos.x += (int)((data->data.mouse.lLastX / 65535.f) * width);
pos.y += (int)((data->data.mouse.lLastY / 65535.f) * height);
ScreenToClient(window->win32.handle, &pos);
dx = pos.x - window->win32.lastCursorPosX;
dy = pos.y - window->win32.lastCursorPosY;
}
else
{
if (data->data.mouse.lLastX || data->data.mouse.lLastY)
{
dx = data->data.mouse.lLastX;
dy = data->data.mouse.lLastY;
}
}
if (dx != 0 || dy != 0)
{
_glfwInputCursorPos(window,
window->virtualCursorPosX + dx,
window->virtualCursorPosY + dy);
window->win32.lastCursorPosX += dx;
window->win32.lastCursorPosY += dy;
}
// Instead of reposting the events, we duplicate the button events' handlers here.
USHORT buttonFlags = data->data.mouse.usButtonFlags;
HWND hwnd = window->win32.handle;
// if any down or up button (anything except RI_MOUSE_WHEEL or RI_MOUSE_HWHEEL), process
if (buttonFlags & 0xFFFF & ~(RI_MOUSE_WHEEL | RI_MOUSE_HWHEEL))
{
int i, button = -1, action = -1;
if (buttonFlags & RI_MOUSE_LEFT_BUTTON_DOWN)
{
button = GLFW_MOUSE_BUTTON_LEFT;
action = GLFW_PRESS;
}
if (buttonFlags & RI_MOUSE_LEFT_BUTTON_UP)
{
button = GLFW_MOUSE_BUTTON_LEFT;
action = GLFW_RELEASE;
}
if (buttonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN)
{
button = GLFW_MOUSE_BUTTON_RIGHT;
action = GLFW_PRESS;
}
if (buttonFlags & RI_MOUSE_RIGHT_BUTTON_UP)
{
button = GLFW_MOUSE_BUTTON_RIGHT;
action = GLFW_RELEASE;
}
if (buttonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN)
{
button = GLFW_MOUSE_BUTTON_MIDDLE;
action = GLFW_PRESS;
}
if (buttonFlags & RI_MOUSE_MIDDLE_BUTTON_UP)
{
button = GLFW_MOUSE_BUTTON_MIDDLE;
action = GLFW_RELEASE;
}
if (buttonFlags & RI_MOUSE_BUTTON_4_DOWN)
{
button = GLFW_MOUSE_BUTTON_4;
action = GLFW_PRESS;
}
if (buttonFlags & RI_MOUSE_BUTTON_4_UP)
{
button = GLFW_MOUSE_BUTTON_4;
action = GLFW_RELEASE;
}
if (buttonFlags & RI_MOUSE_BUTTON_5_DOWN)
{
button = GLFW_MOUSE_BUTTON_5;
action = GLFW_PRESS;
}
if (buttonFlags & RI_MOUSE_BUTTON_5_UP)
{
button = GLFW_MOUSE_BUTTON_5;
action = GLFW_RELEASE;
}
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButtons[i] == GLFW_PRESS)
break;
}
if (i > GLFW_MOUSE_BUTTON_LAST)
SetCapture(hwnd);
_glfwInputMouseClick(window, button, action, getKeyMods());
for (i = 0; i <= GLFW_MOUSE_BUTTON_LAST; i++)
{
if (window->mouseButtons[i] == GLFW_PRESS)
break;
}
if (i > GLFW_MOUSE_BUTTON_LAST)
ReleaseCapture();
}
// Handle mouse wheel events
if (buttonFlags & RI_MOUSE_WHEEL)
{
SHORT wheelDelta = (SHORT)data->data.mouse.usButtonData;
_glfwInputScroll(window, 0.0, wheelDelta / (double) WHEEL_DELTA);
}
if (buttonFlags & RI_MOUSE_HWHEEL)
{
SHORT wheelDelta = (SHORT)data->data.mouse.usButtonData;
_glfwInputScroll(window, -wheelDelta / (double) WHEEL_DELTA, 0.0);
}
}
data = NEXTRAWINPUTBLOCK(data);
}
}
void _glfwPollEventsWin32(void)
{
MSG msg;
HWND handle;
_GLFWwindow* window;
_GLFWwindow* window = _glfw.windowListHead;
_processRawInput(); // this does the whole `GetRawInputBuffer` thing
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
{
@ -2153,7 +2299,8 @@ void _glfwPollEventsWin32(void)
}
window = _glfw.win32.disabledCursorWindow;
if (window)
// Disable with raw mouse motion because that reports dx/dy directly
if (window && !window->rawMouseMotion)
{
int width, height;
_glfwGetWindowSizeWin32(window, &width, &height);

View File

@ -979,7 +979,8 @@ void _glfwTerminateWayland(void)
if (_glfw.wl.cursorTimerfd >= 0)
close(_glfw.wl.cursorTimerfd);
// Free modules only after all wayland termination functions are called
// Free modules only after all Wayland termination functions are called
if (_glfw.egl.handle)
{
_glfwPlatformFreeModule(_glfw.egl.handle);
@ -1003,6 +1004,7 @@ void _glfwTerminateWayland(void)
_glfwPlatformFreeModule(_glfw.wl.xkb.handle);
_glfw.wl.xkb.handle = NULL;
}
if (_glfw.wl.cursor.handle)
{
_glfwPlatformFreeModule(_glfw.wl.cursor.handle);

View File

@ -136,18 +136,22 @@ struct wl_output;
#define GLFW_WAYLAND_MONITOR_STATE _GLFWmonitorWayland wl;
#define GLFW_WAYLAND_CURSOR_STATE _GLFWcursorWayland wl;
struct wl_cursor_image {
struct wl_cursor_image
{
uint32_t width;
uint32_t height;
uint32_t hotspot_x;
uint32_t hotspot_y;
uint32_t delay;
};
struct wl_cursor {
struct wl_cursor
{
unsigned int image_count;
struct wl_cursor_image** images;
char* name;
};
typedef struct wl_cursor_theme* (* PFN_wl_cursor_theme_load)(const char*, int, struct wl_shm*);
typedef void (* PFN_wl_cursor_theme_destroy)(struct wl_cursor_theme*);
typedef struct wl_cursor* (* PFN_wl_cursor_theme_get_cursor)(struct wl_cursor_theme*, const char*);

View File

@ -1413,7 +1413,7 @@ static void handleEvents(double* timeout)
if (read(_glfw.wl.keyRepeatTimerfd, &repeats, sizeof(repeats)) == 8)
{
if(_glfw.wl.keyboardFocus)
if (_glfw.wl.keyboardFocus)
{
for (uint64_t i = 0; i < repeats; i++)
{
@ -1692,7 +1692,8 @@ static void keyboardHandleKeymap(void* userData,
}
mapStr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
if (mapStr == MAP_FAILED) {
if (mapStr == MAP_FAILED)
{
close(fd);
return;
}
@ -1838,7 +1839,9 @@ static void keyboardHandleKey(void* userData,
timer.it_value.tv_nsec = (_glfw.wl.keyRepeatDelay % 1000) * 1000000;
timerfd_settime(_glfw.wl.keyRepeatTimerfd, 0, &timer, NULL);
}
} else if (scancode == _glfw.wl.keyRepeatScancode) {
}
else if (scancode == _glfw.wl.keyRepeatScancode)
{
timerfd_settime(_glfw.wl.keyRepeatTimerfd, 0, &timer, NULL);
}
@ -2974,10 +2977,16 @@ static void lockPointer(_GLFWwindow* window)
if (!_glfw.wl.relativePointerManager)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"Wayland: The compositor does not support pointer locking");
"Wayland: The compositor does not support relative pointer motion");
return;
}
if (!_glfw.wl.pointerConstraints)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"Wayland: The compositor does not support locking the pointer");
}
window->wl.relativePointer =
zwp_relative_pointer_manager_v1_get_relative_pointer(
_glfw.wl.relativePointerManager,
@ -3025,6 +3034,12 @@ static const struct zwp_confined_pointer_v1_listener confinedPointerListener =
static void confinePointer(_GLFWwindow* window)
{
if (!_glfw.wl.pointerConstraints)
{
_glfwInputError(GLFW_FEATURE_UNAVAILABLE,
"Wayland: The compositor does not support confining the pointer");
}
window->wl.confinedPointer =
zwp_pointer_constraints_v1_confine_pointer(
_glfw.wl.pointerConstraints,

View File

@ -151,7 +151,8 @@ void _glfwPollMonitorsX11(void)
}
XRRCrtcInfo* ci = XRRGetCrtcInfo(_glfw.x11.display, sr, oi->crtc);
if (!ci) {
if (!ci)
{
XRRFreeOutputInfo(oi);
continue;
}

View File

@ -2207,10 +2207,10 @@ void _glfwGetWindowSizeX11(_GLFWwindow* window, int* width, int* height)
void _glfwSetWindowSizeX11(_GLFWwindow* window, int width, int height)
{
// The dimensions must be nonzero, or a BadValue error results.
// The dimensions must be nonzero, or a BadValue error results
width = _glfw_max(1, width);
height = _glfw_max(1, height);
if (window->monitor)
{
if (window->monitor->window == window)