Skip to content

Commit 120936f

Browse files
committed
Wayland: Setup next cursor frame callback only if animated
Before, the cursor kept updating for no good reason really. It's also a bit neater and it ever-so-slightly makes `WAYLAND_DEBUG` logs easier to read, although they're still spammed by the window's frame logic (which is needed).
1 parent f289648 commit 120936f

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

platform/linuxbsd/wayland/wayland_thread.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,8 +1231,6 @@ void WaylandThread::_wl_seat_on_capabilities(void *data, struct wl_seat *wl_seat
12311231
// Pointer handling.
12321232
if (capabilities & WL_SEAT_CAPABILITY_POINTER) {
12331233
ss->cursor_surface = wl_compositor_create_surface(ss->registry->wl_compositor);
1234-
ss->cursor_frame_callback = wl_surface_frame(ss->cursor_surface);
1235-
wl_callback_add_listener(ss->cursor_frame_callback, &cursor_frame_callback_listener, ss);
12361234
wl_surface_commit(ss->cursor_surface);
12371235

12381236
ss->wl_pointer = wl_seat_get_pointer(wl_seat);
@@ -1313,11 +1311,9 @@ void WaylandThread::_cursor_frame_callback_on_done(void *data, struct wl_callbac
13131311
SeatState *ss = (SeatState *)data;
13141312
ERR_FAIL_NULL(ss);
13151313

1316-
ss->cursor_time_ms = time_ms;
1314+
ss->cursor_frame_callback = nullptr;
13171315

1318-
ss->cursor_frame_callback = wl_surface_frame(ss->cursor_surface);
1319-
wl_callback_add_listener(ss->cursor_frame_callback, &cursor_frame_callback_listener, ss);
1320-
wl_surface_commit(ss->cursor_surface);
1316+
ss->cursor_time_ms = time_ms;
13211317

13221318
seat_state_update_cursor(ss);
13231319
}
@@ -2899,7 +2895,18 @@ void WaylandThread::seat_state_update_cursor(SeatState *p_ss) {
28992895
// compositor do it for us (badly).
29002896
scale = 1;
29012897
} else if (wl_cursor) {
2902-
int frame_idx = wl_cursor_frame(wl_cursor, p_ss->cursor_time_ms);
2898+
int frame_idx = 0;
2899+
2900+
if (wl_cursor->image_count > 1) {
2901+
// The cursor is animated.
2902+
frame_idx = wl_cursor_frame(wl_cursor, p_ss->cursor_time_ms);
2903+
2904+
if (!p_ss->cursor_frame_callback) {
2905+
// Since it's animated, we'll re-update it the next frame.
2906+
p_ss->cursor_frame_callback = wl_surface_frame(p_ss->cursor_surface);
2907+
wl_callback_add_listener(p_ss->cursor_frame_callback, &cursor_frame_callback_listener, p_ss);
2908+
}
2909+
}
29032910

29042911
struct wl_cursor_image *wl_cursor_image = wl_cursor->images[frame_idx];
29052912

0 commit comments

Comments
 (0)