Compare commits

...

11 Commits

Author SHA1 Message Date
JakobDev
ef60120ec1
Merge adcb0bda78 into 232164f62b 2026-02-06 10:26:32 +00:00
Camilla Löwy
232164f62b Wayland: Remove duplicate cursor state
The shared window struct already tracks the current cursor.
2026-02-05 17:28:32 +01:00
Camilla Löwy
abb9db0d75 Wayland: Fix fallback decoration button input
Fallback decoration mouse button actions were performed for both press
and release events.  The requests made using a mouse button release
serials were presumably (and correctly) discarded by the compositor.

This commit removes the generation of these nuisance requests.
2026-02-05 17:25:11 +01:00
Camilla Löwy
0aa77a9a3a Wayland: Release input devices where possible
On systems with wl_seat verison 3 or later, use release instead of
destroy on input devices when they are disconnected.
2026-02-04 18:08:37 +01:00
Camilla Löwy
7b370d8df0 Wayland: Simplify pointer surface state
Track which surface contains the pointer with one piece of state instead
of three partially overlapping ones.
2026-02-04 18:08:37 +01:00
Camilla Löwy
f871f14d5e Add update flag to timeout test
Redrawing the window contents for every possible event is not
a reasonable thing for an application to do.  The test should be whether
redrawing on demand plus periodic updates works with near-idle CPU use
and no extra input latency.

This change incidentally makes the test well-behaved on Wayland, where
it was previously broken due to every EGL buffer swap causing an event
to be received.
2026-02-04 18:07:19 +01:00
Camilla Löwy
bafb134769 Documentation work
Elaborate on what 'work' means in the context of joystick input.
2026-01-27 20:51:00 +01:00
Camilla Löwy
2d7ae8f2d0 Wayland: Cleanup
This is only a semantic change.  The values are the same.
2026-01-15 21:09:01 +01:00
Camilla Löwy
96e0f49395 X11: Place argument assertion after platform check
This lets automated testing check that GLFW_NOT_INITIALIZED is emitted
for every public function.
2026-01-14 21:03:13 +01:00
JakobDev
adcb0bda78
Fix 2025-01-28 17:36:59 +01:00
JakobDev
69cc9fe0a8
Wayland: Implement cursor-shape-v1 protocol 2025-01-28 17:24:05 +01:00
9 changed files with 1528 additions and 71 deletions

152
deps/wayland/cursor-shape-v1.xml vendored Normal file
View File

@ -0,0 +1,152 @@
<?xml version="1.0" encoding="UTF-8"?>
<protocol name="cursor_shape_v1">
<copyright>
Copyright 2018 The Chromium Authors
Copyright 2023 Simon Ser
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
</copyright>
<interface name="wp_cursor_shape_manager_v1" version="1">
<description summary="cursor shape manager">
This global offers an alternative, optional way to set cursor images. This
new way uses enumerated cursors instead of a wl_surface like
wl_pointer.set_cursor does.
Warning! The protocol described in this file is currently in the testing
phase. Backward compatible changes may be added together with the
corresponding interface version bump. Backward incompatible changes can
only be done by creating a new major version of the extension.
</description>
<request name="destroy" type="destructor">
<description summary="destroy the manager">
Destroy the cursor shape manager.
</description>
</request>
<request name="get_pointer">
<description summary="manage the cursor shape of a pointer device">
Obtain a wp_cursor_shape_device_v1 for a wl_pointer object.
When the pointer capability is removed from the wl_seat, the
wp_cursor_shape_device_v1 object becomes inert.
</description>
<arg name="cursor_shape_device" type="new_id" interface="wp_cursor_shape_device_v1"/>
<arg name="pointer" type="object" interface="wl_pointer"/>
</request>
<request name="get_tablet_tool_v2">
<description summary="manage the cursor shape of a tablet tool device">
Obtain a wp_cursor_shape_device_v1 for a zwp_tablet_tool_v2 object.
When the zwp_tablet_tool_v2 is removed, the wp_cursor_shape_device_v1
object becomes inert.
</description>
<arg name="cursor_shape_device" type="new_id" interface="wp_cursor_shape_device_v1"/>
<arg name="tablet_tool" type="object" interface="zwp_tablet_tool_v2"/>
</request>
</interface>
<interface name="wp_cursor_shape_device_v1" version="1">
<description summary="cursor shape for a device">
This interface allows clients to set the cursor shape.
</description>
<enum name="shape">
<description summary="cursor shapes">
This enum describes cursor shapes.
The names are taken from the CSS W3C specification:
https://w3c.github.io/csswg-drafts/css-ui/#cursor
</description>
<entry name="default" value="1" summary="default cursor"/>
<entry name="context_menu" value="2" summary="a context menu is available for the object under the cursor"/>
<entry name="help" value="3" summary="help is available for the object under the cursor"/>
<entry name="pointer" value="4" summary="pointer that indicates a link or another interactive element"/>
<entry name="progress" value="5" summary="progress indicator"/>
<entry name="wait" value="6" summary="program is busy, user should wait"/>
<entry name="cell" value="7" summary="a cell or set of cells may be selected"/>
<entry name="crosshair" value="8" summary="simple crosshair"/>
<entry name="text" value="9" summary="text may be selected"/>
<entry name="vertical_text" value="10" summary="vertical text may be selected"/>
<entry name="alias" value="11" summary="drag-and-drop: alias of/shortcut to something is to be created"/>
<entry name="copy" value="12" summary="drag-and-drop: something is to be copied"/>
<entry name="move" value="13" summary="drag-and-drop: something is to be moved"/>
<entry name="no_drop" value="14" summary="drag-and-drop: the dragged item cannot be dropped at the current cursor location"/>
<entry name="not_allowed" value="15" summary="drag-and-drop: the requested action will not be carried out"/>
<entry name="grab" value="16" summary="drag-and-drop: something can be grabbed"/>
<entry name="grabbing" value="17" summary="drag-and-drop: something is being grabbed"/>
<entry name="e_resize" value="18" summary="resizing: the east border is to be moved"/>
<entry name="n_resize" value="19" summary="resizing: the north border is to be moved"/>
<entry name="ne_resize" value="20" summary="resizing: the north-east corner is to be moved"/>
<entry name="nw_resize" value="21" summary="resizing: the north-west corner is to be moved"/>
<entry name="s_resize" value="22" summary="resizing: the south border is to be moved"/>
<entry name="se_resize" value="23" summary="resizing: the south-east corner is to be moved"/>
<entry name="sw_resize" value="24" summary="resizing: the south-west corner is to be moved"/>
<entry name="w_resize" value="25" summary="resizing: the west border is to be moved"/>
<entry name="ew_resize" value="26" summary="resizing: the east and west borders are to be moved"/>
<entry name="ns_resize" value="27" summary="resizing: the north and south borders are to be moved"/>
<entry name="nesw_resize" value="28" summary="resizing: the north-east and south-west corners are to be moved"/>
<entry name="nwse_resize" value="29" summary="resizing: the north-west and south-east corners are to be moved"/>
<entry name="col_resize" value="30" summary="resizing: that the item/column can be resized horizontally"/>
<entry name="row_resize" value="31" summary="resizing: that the item/row can be resized vertically"/>
<entry name="all_scroll" value="32" summary="something can be scrolled in any direction"/>
<entry name="zoom_in" value="33" summary="something can be zoomed in"/>
<entry name="zoom_out" value="34" summary="something can be zoomed out"/>
</enum>
<enum name="error">
<entry name="invalid_shape" value="1"
summary="the specified shape value is invalid"/>
</enum>
<request name="destroy" type="destructor">
<description summary="destroy the cursor shape device">
Destroy the cursor shape device.
The device cursor shape remains unchanged.
</description>
</request>
<request name="set_shape">
<description summary="set device cursor to the shape">
Sets the device cursor to the specified shape. The compositor will
change the cursor image based on the specified shape.
The cursor actually changes only if the input device focus is one of
the requesting client's surfaces. If any, the previous cursor image
(surface or shape) is replaced.
The "shape" argument must be a valid enum entry, otherwise the
invalid_shape protocol error is raised.
This is similar to the wl_pointer.set_cursor and
zwp_tablet_tool_v2.set_cursor requests, but this request accepts a
shape instead of contents in the form of a surface. Clients can mix
set_cursor and set_shape requests.
The serial parameter must match the latest wl_pointer.enter or
zwp_tablet_tool_v2.proximity_in serial number sent to the client.
Otherwise the request will be ignored.
</description>
<arg name="serial" type="uint" summary="serial number of the enter event"/>
<arg name="shape" type="uint" enum="shape"/>
</request>
</interface>
</protocol>

1182
deps/wayland/tablet-unstable-v2.xml vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -4520,7 +4520,8 @@ GLFWAPI GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow*
* GLFW will pass those events on to the application callbacks before
* returning.
*
* Event processing is not required for joystick input to work.
* Event processing is not required to receive joystick input. Joystick state
* is polled when a joystick input or gamepad input function is called.
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR.
@ -4565,7 +4566,8 @@ GLFWAPI void glfwPollEvents(void);
* GLFW will pass those events on to the application callbacks before
* returning.
*
* Event processing is not required for joystick input to work.
* Event processing is not required to receive joystick input. Joystick state
* is polled when a joystick input or gamepad input function is called.
*
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref
* GLFW_PLATFORM_ERROR.
@ -4612,7 +4614,8 @@ GLFWAPI void glfwWaitEvents(void);
* GLFW will pass those events on to the application callbacks before
* returning.
*
* Event processing is not required for joystick input to work.
* Event processing is not required to receive joystick input. Joystick state
* is polled when a joystick input or gamepad input function is called.
*
* @param[in] timeout The maximum amount of time, in seconds, to wait.
*

View File

@ -105,6 +105,8 @@ if (GLFW_BUILD_WAYLAND)
generate_wayland_protocol("fractional-scale-v1.xml")
generate_wayland_protocol("xdg-activation-v1.xml")
generate_wayland_protocol("xdg-decoration-unstable-v1.xml")
generate_wayland_protocol("tablet-unstable-v2.xml")
generate_wayland_protocol("cursor-shape-v1.xml")
endif()
if (WIN32 AND GLFW_BUILD_SHARED_LIBRARY)

View File

@ -49,6 +49,8 @@
#include "fractional-scale-v1-client-protocol.h"
#include "xdg-activation-v1-client-protocol.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#include "tablet-unstable-v2-client-protocol.h"
#include "cursor-shape-v1-client-protocol.h"
// NOTE: Versions of wayland-scanner prior to 1.17.91 named every global array of
// wl_interface pointers 'types', making it impossible to combine several unmodified
@ -91,6 +93,14 @@
#include "idle-inhibit-unstable-v1-client-protocol-code.h"
#undef types
#define types _glfw_tablet_types
#include "tablet-unstable-v2-client-protocol-code.h"
#undef types
#define types _glfw_cursor_shape_types
#include "cursor-shape-v1-client-protocol-code.h"
#undef types
static void wmBaseHandlePing(void* userData,
struct xdg_wm_base* wmBase,
uint32_t serial)
@ -208,6 +218,13 @@ static void registryHandleGlobal(void* userData,
&wp_fractional_scale_manager_v1_interface,
1);
}
else if (strcmp(interface, wp_cursor_shape_manager_v1_interface.name) == 0)
{
_glfw.wl.cursorShapeManager =
wl_registry_bind(registry, name,
&wp_cursor_shape_manager_v1_interface,
1);
}
}
static void registryHandleGlobalRemove(void* userData,
@ -834,7 +851,7 @@ int _glfwInitWayland(void)
createKeyTables();
_glfw.wl.xkb.context = xkb_context_new(0);
_glfw.wl.xkb.context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
if (!_glfw.wl.xkb.context)
{
_glfwInputError(GLFW_PLATFORM_ERROR,
@ -966,6 +983,10 @@ void _glfwTerminateWayland(void)
xdg_activation_v1_destroy(_glfw.wl.activationManager);
if (_glfw.wl.fractionalScaleManager)
wp_fractional_scale_manager_v1_destroy(_glfw.wl.fractionalScaleManager);
if (_glfw.wl.cursorShapeManager)
wp_cursor_shape_manager_v1_destroy(_glfw.wl.cursorShapeManager);
if (_glfw.wl.cursorShapeDevice)
wp_cursor_shape_device_v1_destroy(_glfw.wl.cursorShapeDevice);
if (_glfw.wl.registry)
wl_registry_destroy(_glfw.wl.registry);
if (_glfw.wl.display)

View File

@ -360,7 +360,6 @@ typedef struct _GLFWwindowWayland
GLFWbool maximized;
GLFWbool activated;
GLFWbool fullscreen;
GLFWbool hovered;
GLFWbool transparent;
GLFWbool scaleFramebuffer;
struct wl_surface* surface;
@ -389,7 +388,6 @@ typedef struct _GLFWwindowWayland
struct libdecor_frame* frame;
} libdecor;
_GLFWcursor* currentCursor;
double cursorPosX, cursorPosY;
char* appId;
@ -416,7 +414,6 @@ typedef struct _GLFWwindowWayland
GLFWbool decorations;
struct wl_buffer* buffer;
_GLFWfallbackEdgeWayland top, left, right, bottom;
struct wl_surface* focus;
wl_fixed_t pointerX, pointerY;
const char* cursorName;
} fallback;
@ -444,6 +441,8 @@ typedef struct _GLFWlibraryWayland
struct zwp_idle_inhibit_manager_v1* idleInhibitManager;
struct xdg_activation_v1* activationManager;
struct wp_fractional_scale_manager_v1* fractionalScaleManager;
struct wp_cursor_shape_manager_v1* cursorShapeManager;
struct wp_cursor_shape_device_v1* cursorShapeDevice;
_GLFWofferWayland* offers;
unsigned int offerCount;
@ -457,6 +456,7 @@ typedef struct _GLFWlibraryWayland
const char* tag;
struct wl_surface* pointerSurface;
struct wl_cursor_theme* cursorTheme;
struct wl_cursor_theme* cursorThemeHiDPI;
struct wl_surface* cursorSurface;
@ -515,7 +515,6 @@ typedef struct _GLFWlibraryWayland
PFN_xkb_compose_state_get_one_sym compose_state_get_one_sym;
} xkb;
_GLFWwindow* pointerFocus;
_GLFWwindow* keyboardFocus;
struct {
@ -614,6 +613,7 @@ typedef struct _GLFWcursorWayland
int width, height;
int xhot, yhot;
int currentImage;
int shape;
} _GLFWcursorWayland;
GLFWbool _glfwConnectWayland(int platformID, _GLFWplatform* platform);

View File

@ -51,6 +51,7 @@
#include "xdg-activation-v1-client-protocol.h"
#include "idle-inhibit-unstable-v1-client-protocol.h"
#include "fractional-scale-v1-client-protocol.h"
#include "cursor-shape-v1-client-protocol.h"
#define GLFW_BORDER_SIZE 4
#define GLFW_CAPTION_HEIGHT 24
@ -253,6 +254,9 @@ static void createFallbackDecorations(_GLFWwindow* window)
static void destroyFallbackEdge(_GLFWfallbackEdgeWayland* edge)
{
if (edge->surface == _glfw.wl.pointerSurface)
_glfw.wl.pointerSurface = NULL;
if (edge->subsurface)
wl_subsurface_destroy(edge->subsurface);
if (edge->surface)
@ -288,26 +292,26 @@ static void updateFallbackDecorationCursor(_GLFWwindow* window,
if (window->resizable)
{
if (window->wl.fallback.focus == window->wl.fallback.top.surface)
if (_glfw.wl.pointerSurface == window->wl.fallback.top.surface)
{
if (ypos < GLFW_BORDER_SIZE)
cursorName = "n-resize";
}
else if (window->wl.fallback.focus == window->wl.fallback.left.surface)
else if (_glfw.wl.pointerSurface == window->wl.fallback.left.surface)
{
if (ypos < GLFW_BORDER_SIZE)
cursorName = "nw-resize";
else
cursorName = "w-resize";
}
else if (window->wl.fallback.focus == window->wl.fallback.right.surface)
else if (_glfw.wl.pointerSurface == window->wl.fallback.right.surface)
{
if (ypos < GLFW_BORDER_SIZE)
cursorName = "ne-resize";
else
cursorName = "e-resize";
}
else if (window->wl.fallback.focus == window->wl.fallback.bottom.surface)
else if (_glfw.wl.pointerSurface == window->wl.fallback.bottom.surface)
{
if (xpos < GLFW_BORDER_SIZE)
cursorName = "sw-resize";
@ -360,8 +364,12 @@ static void updateFallbackDecorationCursor(_GLFWwindow* window,
static void handleFallbackDecorationButton(_GLFWwindow* window,
uint32_t serial,
uint32_t button)
uint32_t button,
uint32_t state)
{
if (state != WL_POINTER_BUTTON_STATE_PRESSED)
return;
const double xpos = wl_fixed_to_double(window->wl.fallback.pointerX);
const double ypos = wl_fixed_to_double(window->wl.fallback.pointerY);
@ -369,28 +377,28 @@ static void handleFallbackDecorationButton(_GLFWwindow* window,
{
uint32_t edges = XDG_TOPLEVEL_RESIZE_EDGE_NONE;
if (window->wl.fallback.focus == window->wl.fallback.top.surface)
if (_glfw.wl.pointerSurface == window->wl.fallback.top.surface)
{
if (ypos < GLFW_BORDER_SIZE)
edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP;
else
xdg_toplevel_move(window->wl.xdg.toplevel, _glfw.wl.seat, serial);
}
else if (window->wl.fallback.focus == window->wl.fallback.left.surface)
else if (_glfw.wl.pointerSurface == window->wl.fallback.left.surface)
{
if (ypos < GLFW_BORDER_SIZE)
edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP_LEFT;
else
edges = XDG_TOPLEVEL_RESIZE_EDGE_LEFT;
}
else if (window->wl.fallback.focus == window->wl.fallback.right.surface)
else if (_glfw.wl.pointerSurface == window->wl.fallback.right.surface)
{
if (ypos < GLFW_BORDER_SIZE)
edges = XDG_TOPLEVEL_RESIZE_EDGE_TOP_RIGHT;
else
edges = XDG_TOPLEVEL_RESIZE_EDGE_RIGHT;
}
else if (window->wl.fallback.focus == window->wl.fallback.bottom.surface)
else if (_glfw.wl.pointerSurface == window->wl.fallback.bottom.surface)
{
if (xpos < GLFW_BORDER_SIZE)
edges = XDG_TOPLEVEL_RESIZE_EDGE_BOTTOM_LEFT;
@ -408,7 +416,7 @@ static void handleFallbackDecorationButton(_GLFWwindow* window,
if (!window->wl.xdg.toplevel)
return;
if (window->wl.fallback.focus != window->wl.fallback.top.surface)
if (_glfw.wl.pointerSurface != window->wl.fallback.top.surface)
return;
if (ypos < GLFW_BORDER_SIZE)
@ -1221,9 +1229,67 @@ static GLFWbool createNativeSurface(_GLFWwindow* window,
return GLFW_TRUE;
}
GLFWbool setCursorShape(int shape) {
int xdgShape = -1;
switch (shape)
{
case GLFW_ARROW_CURSOR:
xdgShape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_DEFAULT;
break;
case GLFW_IBEAM_CURSOR:
xdgShape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT;
break;
case GLFW_CROSSHAIR_CURSOR:
xdgShape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_CROSSHAIR;
break;
case GLFW_POINTING_HAND_CURSOR:
xdgShape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_POINTER;
break;
case GLFW_RESIZE_EW_CURSOR:
xdgShape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_EW_RESIZE;
break;
case GLFW_RESIZE_NS_CURSOR:
xdgShape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NS_RESIZE;
break;
case GLFW_RESIZE_NWSE_CURSOR:
xdgShape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NWSE_RESIZE;
break;
case GLFW_RESIZE_NESW_CURSOR:
xdgShape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NESW_RESIZE;
break;
case GLFW_RESIZE_ALL_CURSOR:
xdgShape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_ALL_SCROLL;
break;
case GLFW_NOT_ALLOWED_CURSOR:
xdgShape = WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_NOT_ALLOWED;
break;
}
if (xdgShape == -1)
{
return GLFW_FALSE;
}
wp_cursor_shape_device_v1_set_shape(_glfw.wl.cursorShapeDevice,
_glfw.wl.pointerEnterSerial,
xdgShape);
return GLFW_TRUE;
}
static void setCursorImage(_GLFWwindow* window,
_GLFWcursorWayland* cursorWayland)
{
if (_glfw.wl.cursorShapeDevice && cursorWayland->shape != 0)
{
GLFWbool ok = setCursorShape(cursorWayland->shape);
if (ok == GLFW_TRUE)
{
return;
}
}
struct itimerspec timer = {0};
struct wl_cursor* wlCursor = cursorWayland->cursor;
struct wl_cursor_image* image;
@ -1267,14 +1333,16 @@ static void setCursorImage(_GLFWwindow* window,
wl_surface_commit(surface);
}
static void incrementCursorImage(_GLFWwindow* window)
static void incrementCursorImage(void)
{
_GLFWcursor* cursor;
if (!window || !window->wl.hovered)
if (!_glfw.wl.pointerSurface)
return;
cursor = window->wl.currentCursor;
_GLFWwindow* window = wl_surface_get_user_data(_glfw.wl.pointerSurface);
if (window->wl.surface != _glfw.wl.pointerSurface)
return;
_GLFWcursor* cursor = window->cursor;
if (cursor && cursor->wl.cursor)
{
cursor->wl.currentImage += 1;
@ -1436,7 +1504,7 @@ static void handleEvents(double* timeout)
uint64_t repeats;
if (read(_glfw.wl.cursorTimerfd, &repeats, sizeof(repeats)) == 8)
incrementCursorImage(_glfw.wl.pointerFocus);
incrementCursorImage();
}
if (fds[LIBDECOR_FD].revents & POLLIN)
@ -1527,16 +1595,14 @@ static void pointerHandleEnter(void* userData,
if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag)
return;
_GLFWwindow* window = wl_surface_get_user_data(surface);
_glfw.wl.serial = serial;
_glfw.wl.pointerEnterSerial = serial;
_glfw.wl.pointerFocus = window;
_glfw.wl.pointerSurface = surface;
if (surface == window->wl.surface)
_GLFWwindow* window = wl_surface_get_user_data(surface);
if (window->wl.surface == surface)
{
window->wl.hovered = GLFW_TRUE;
_glfwSetCursorWayland(window, window->wl.currentCursor);
_glfwSetCursorWayland(window, window->cursor);
_glfwInputCursorEnter(window, GLFW_TRUE);
if (window->cursorMode != GLFW_CURSOR_DISABLED)
@ -1549,11 +1615,8 @@ static void pointerHandleEnter(void* userData,
else
{
if (window->wl.fallback.decorations)
{
window->wl.fallback.focus = surface;
updateFallbackDecorationCursor(window, sx, sy);
}
}
}
static void pointerHandleLeave(void* userData,
@ -1567,26 +1630,17 @@ static void pointerHandleLeave(void* userData,
if (wl_proxy_get_tag((struct wl_proxy*) surface) != &_glfw.wl.tag)
return;
_GLFWwindow* window = _glfw.wl.pointerFocus;
if (!window)
return;
_glfw.wl.serial = serial;
_glfw.wl.pointerFocus = NULL;
_glfw.wl.pointerSurface = NULL;
if (window->wl.hovered)
{
window->wl.hovered = GLFW_FALSE;
_GLFWwindow* window = wl_surface_get_user_data(surface);
if (window->wl.surface == surface)
_glfwInputCursorEnter(window, GLFW_FALSE);
}
else
{
if (window->wl.fallback.decorations)
{
window->wl.fallback.focus = NULL;
window->wl.fallback.cursorName = NULL;
}
}
}
static void pointerHandleMotion(void* userData,
@ -1595,14 +1649,15 @@ static void pointerHandleMotion(void* userData,
wl_fixed_t sx,
wl_fixed_t sy)
{
_GLFWwindow* window = _glfw.wl.pointerFocus;
if (!window)
if (!_glfw.wl.pointerSurface)
return;
_GLFWwindow* window = wl_surface_get_user_data(_glfw.wl.pointerSurface);
if (window->cursorMode == GLFW_CURSOR_DISABLED)
return;
if (window->wl.hovered)
if (window->wl.surface == _glfw.wl.pointerSurface)
{
window->wl.cursorPosX = wl_fixed_to_double(sx);
window->wl.cursorPosY = wl_fixed_to_double(sy);
@ -1622,11 +1677,12 @@ static void pointerHandleButton(void* userData,
uint32_t button,
uint32_t state)
{
_GLFWwindow* window = _glfw.wl.pointerFocus;
if (!window)
if (!_glfw.wl.pointerSurface)
return;
if (window->wl.hovered)
_GLFWwindow* window = wl_surface_get_user_data(_glfw.wl.pointerSurface);
if (window->wl.surface == _glfw.wl.pointerSurface)
{
_glfw.wl.serial = serial;
@ -1638,7 +1694,7 @@ static void pointerHandleButton(void* userData,
else
{
if (window->wl.fallback.decorations)
handleFallbackDecorationButton(window, serial, button);
handleFallbackDecorationButton(window, serial, button, state);
}
}
@ -1648,11 +1704,12 @@ static void pointerHandleAxis(void* userData,
uint32_t axis,
wl_fixed_t value)
{
_GLFWwindow* window = _glfw.wl.pointerFocus;
if (!window)
if (!_glfw.wl.pointerSurface)
return;
if (window->wl.hovered)
_GLFWwindow* window = wl_surface_get_user_data(_glfw.wl.pointerSurface);
if (window->wl.surface == _glfw.wl.pointerSurface)
{
// NOTE: 10 units of motion per mouse wheel step seems to be a common ratio
if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL)
@ -1701,7 +1758,7 @@ static void keyboardHandleKeymap(void* userData,
keymap = xkb_keymap_new_from_string(_glfw.wl.xkb.context,
mapStr,
XKB_KEYMAP_FORMAT_TEXT_V1,
0);
XKB_KEYMAP_COMPILE_NO_FLAGS);
munmap(mapStr, size);
close(fd);
@ -1929,10 +1986,18 @@ static void seatHandleCapabilities(void* userData,
{
_glfw.wl.pointer = wl_seat_get_pointer(seat);
wl_pointer_add_listener(_glfw.wl.pointer, &pointerListener, NULL);
if (_glfw.wl.cursorShapeManager)
{
_glfw.wl.cursorShapeDevice = wp_cursor_shape_manager_v1_get_pointer(_glfw.wl.cursorShapeManager, _glfw.wl.pointer);
}
}
else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && _glfw.wl.pointer)
{
if (wl_pointer_get_version(_glfw.wl.pointer) >= WL_POINTER_RELEASE_SINCE_VERSION)
wl_pointer_release(_glfw.wl.pointer);
else
wl_pointer_destroy(_glfw.wl.pointer);
_glfw.wl.pointer = NULL;
}
@ -1943,7 +2008,11 @@ static void seatHandleCapabilities(void* userData,
}
else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && _glfw.wl.keyboard)
{
if (wl_keyboard_get_version(_glfw.wl.keyboard) >= WL_KEYBOARD_RELEASE_SINCE_VERSION)
wl_keyboard_release(_glfw.wl.keyboard);
else
wl_keyboard_destroy(_glfw.wl.keyboard);
_glfw.wl.keyboard = NULL;
}
}
@ -2223,8 +2292,8 @@ GLFWbool _glfwCreateWindowWayland(_GLFWwindow* window,
void _glfwDestroyWindowWayland(_GLFWwindow* window)
{
if (window == _glfw.wl.pointerFocus)
_glfw.wl.pointerFocus = NULL;
if (window->wl.surface == _glfw.wl.pointerSurface)
_glfw.wl.pointerSurface = NULL;
if (window == _glfw.wl.keyboardFocus)
{
@ -2600,7 +2669,7 @@ GLFWbool _glfwWindowMaximizedWayland(_GLFWwindow* window)
GLFWbool _glfwWindowHoveredWayland(_GLFWwindow* window)
{
return window->wl.hovered;
return window->wl.surface == _glfw.wl.pointerSurface;
}
GLFWbool _glfwFramebufferTransparentWayland(_GLFWwindow* window)
@ -2730,7 +2799,7 @@ void _glfwSetCursorPosWayland(_GLFWwindow* window, double x, double y)
void _glfwSetCursorModeWayland(_GLFWwindow* window, int mode)
{
_glfwSetCursorWayland(window, window->wl.currentCursor);
_glfwSetCursorWayland(window, window->cursor);
}
const char* _glfwGetScancodeNameWayland(int scancode)
@ -2812,6 +2881,8 @@ GLFWbool _glfwCreateCursorWayland(_GLFWcursor* cursor,
GLFWbool _glfwCreateStandardCursorWayland(_GLFWcursor* cursor, int shape)
{
cursor->wl.shape = shape;
const char* name = NULL;
// Try the XDG names first
@ -3064,11 +3135,7 @@ void _glfwSetCursorWayland(_GLFWwindow* window, _GLFWcursor* cursor)
if (!_glfw.wl.pointer)
return;
window->wl.currentCursor = cursor;
// If we're not in the correct window just save the cursor
// the next time the pointer enters the window the cursor will change
if (!window->wl.hovered)
if (window->wl.surface != _glfw.wl.pointerSurface)
return;
// Update pointer lock to match cursor mode
@ -3125,7 +3192,8 @@ void _glfwSetCursorWayland(_GLFWwindow* window, _GLFWcursor* cursor)
NULL,
0, 0,
0, 0,
0
0,
GLFW_ARROW_CURSOR
};
setCursorImage(window, &cursorWayland);

View File

@ -3344,8 +3344,6 @@ GLFWAPI Window glfwGetX11Window(GLFWwindow* handle)
GLFWAPI void glfwSetX11SelectionString(const char* string)
{
assert(string != NULL);
_GLFW_REQUIRE_INIT();
if (_glfw.platform.platformID != GLFW_PLATFORM_X11)
@ -3354,6 +3352,8 @@ GLFWAPI void glfwSetX11SelectionString(const char* string)
return;
}
assert(string != NULL);
_glfw_free(_glfw.x11.primarySelectionString);
_glfw.x11.primarySelectionString = _glfw_strdup(string);

View File

@ -36,6 +36,14 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
static bool needs_update;
static void window_close_callback(GLFWwindow* window)
{
needs_update = true;
}
static void error_callback(int error, const char* description)
{
@ -45,7 +53,15 @@ static void error_callback(int error, const char* description)
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
{
glfwSetWindowShouldClose(window, GLFW_TRUE);
needs_update = true;
}
}
static void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
needs_update = true;
}
static float nrand(void)
@ -72,8 +88,11 @@ int main(void)
}
glfwMakeContextCurrent(window);
glfwSwapInterval(0);
gladLoadGL(glfwGetProcAddress);
glfwSetWindowCloseCallback(window, window_close_callback);
glfwSetKeyCallback(window, key_callback);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
while (!glfwWindowShouldClose(window))
{
@ -87,8 +106,18 @@ int main(void)
glClearColor(r / l, g / l, b / l, 1.f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
needs_update = false;
glfwWaitEventsTimeout(1.0);
const double start = glfwGetTime();
while (!needs_update)
{
const double elapsed = glfwGetTime() - start;
if (elapsed >= 1.0)
needs_update = true;
else
glfwWaitEventsTimeout(1.0 - elapsed);
}
}
glfwDestroyWindow(window);