From a213ee960a95815b5bc409f132c704c54948c91a Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 31 Jul 2021 04:01:51 -0400 Subject: [PATCH] [client] wayland: implement signalNextFrame with frame callbacks --- client/displayservers/Wayland/wayland.c | 1 + client/displayservers/Wayland/wayland.h | 1 + client/displayservers/Wayland/window.c | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/client/displayservers/Wayland/wayland.c b/client/displayservers/Wayland/wayland.c index 78cf8714..0ee9a292 100644 --- a/client/displayservers/Wayland/wayland.c +++ b/client/displayservers/Wayland/wayland.c @@ -164,6 +164,7 @@ struct LG_DisplayServerOps LGDS_Wayland = .glSetSwapInterval = waylandGLSetSwapInterval, .glSwapBuffers = waylandGLSwapBuffers, #endif + .signalNextFrame = waylandSignalNextFrame, .guestPointerUpdated = waylandGuestPointerUpdated, .setPointer = waylandSetPointer, .grabPointer = waylandGrabPointer, diff --git a/client/displayservers/Wayland/wayland.h b/client/displayservers/Wayland/wayland.h index 2f208b35..14f6bfa6 100644 --- a/client/displayservers/Wayland/wayland.h +++ b/client/displayservers/Wayland/wayland.h @@ -289,3 +289,4 @@ void waylandWindowFree(void); void waylandWindowUpdateScale(void); void waylandSetWindowSize(int x, int y); bool waylandIsValidPointerPos(int x, int y); +void waylandSignalNextFrame(LGEvent * event); diff --git a/client/displayservers/Wayland/window.c b/client/displayservers/Wayland/window.c index edea79e6..5504108d 100644 --- a/client/displayservers/Wayland/window.c +++ b/client/displayservers/Wayland/window.c @@ -27,6 +27,7 @@ #include "app.h" #include "common/debug.h" +#include "common/event.h" // Surface-handling listeners. @@ -114,3 +115,21 @@ bool waylandIsValidPointerPos(int x, int y) { return x >= 0 && x < wlWm.width && y >= 0 && y < wlWm.height; } + +static void frameHandler(void * opaque, struct wl_callback * callback, unsigned int data) +{ + LGEvent * event = opaque; + lgSignalEvent(event); + wl_callback_destroy(callback); +} + +static const struct wl_callback_listener frame_listener = { + .done = frameHandler, +}; + +void waylandSignalNextFrame(LGEvent * event) +{ + struct wl_callback * callback = wl_surface_frame(wlWm.surface); + if (callback) + wl_callback_add_listener(callback, &frame_listener, event); +}