Skip to content

Commit 2cb884b

Browse files
committed
Merge pull request #89328 from Riteo/wayland-cursor-frame-opt
Wayland: Setup next cursor frame callback only if animated
2 parents 30d08f0 + 120936f commit 2cb884b

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
}
@@ -2919,7 +2915,18 @@ void WaylandThread::seat_state_update_cursor(SeatState *p_ss) {
29192915
// compositor do it for us (badly).
29202916
scale = 1;
29212917
} else if (wl_cursor) {
2922-
int frame_idx = wl_cursor_frame(wl_cursor, p_ss->cursor_time_ms);
2918+
int frame_idx = 0;
2919+
2920+
if (wl_cursor->image_count > 1) {
2921+
// The cursor is animated.
2922+
frame_idx = wl_cursor_frame(wl_cursor, p_ss->cursor_time_ms);
2923+
2924+
if (!p_ss->cursor_frame_callback) {
2925+
// Since it's animated, we'll re-update it the next frame.
2926+
p_ss->cursor_frame_callback = wl_surface_frame(p_ss->cursor_surface);
2927+
wl_callback_add_listener(p_ss->cursor_frame_callback, &cursor_frame_callback_listener, p_ss);
2928+
}
2929+
}
29232930

29242931
struct wl_cursor_image *wl_cursor_image = wl_cursor->images[frame_idx];
29252932

0 commit comments

Comments
 (0)