This commit is contained in:
Jorijn van der Graaf 2025-11-16 20:42:48 +01:00
commit e795ab880c
6 changed files with 89 additions and 24 deletions

View file

@ -55,6 +55,34 @@ xdg_wm_base_listener xdgWmBaseListener = {
.ping = xdg_wm_base_handle_ping,
};
void WindowWayland::wl_surface_frame_done(void *data, struct wl_callback *cb, uint32_t time)
{
/* Destroy this callback */
wl_callback_destroy(cb);
/* Request another frame */
struct client_state *state = data;
cb = wl_surface_frame(state->wl_surface);
wl_callback_add_listener(cb, &wl_surface_frame_listener, state);
/* Update scroll amount at 24 pixels per second */
if (state->last_frame != 0) {
int elapsed = time - state->last_frame;
state->offset += elapsed / 1000.0 * 24;
}
/* Submit a frame for this event */
struct wl_buffer *buffer = draw_frame(state);
wl_surface_attach(state->wl_surface, buffer, 0, 0);
wl_surface_damage_buffer(state->wl_surface, 0, 0, INT32_MAX, INT32_MAX);
wl_surface_commit(state->wl_surface);
state->last_frame = time;
}
wl_callback_listener WindowWayland::surface_frame_listener = {
.done = wl_surface_frame_done,
};
void WindowWayland::pointer_handle_button(void* data, wl_pointer* pointer, std::uint32_t serial, std::uint32_t time, std::uint32_t button, std::uint32_t state) {
WindowWayland* window = reinterpret_cast<WindowWayland*>(data);
@ -333,12 +361,15 @@ WindowWayland::WindowWayland(std::string name, std::uint32_t width, std::uint32_
surface = wl_compositor_create_surface(compositor);
xdgSurface = xdg_wm_base_get_xdg_surface(xdgWmBase, surface);
xdgToplevel = xdg_surface_get_toplevel(xdgSurface);
cb = wl_surface_frame(surface);
+ wl_callback_add_listener(cb, &wl_surface_frame_listener, this);
xdg_surface_add_listener(xdgSurface, &xdg_surface_listener, this);
xdg_toplevel_add_listener(xdgToplevel, &xdg_toplevel_listener, this);
wl_surface_commit(surface);
xdg_toplevel_set_title(xdg_toplevel, name.c_str());
while (wl_display_dispatch(display) != -1 && !configured) {
// This space intentionally left blank
}
@ -353,5 +384,6 @@ WindowWayland::~WindowWayland() {
xdg_toplevel_destroy(xdgToplevel);
xdg_surface_destroy(xdgSurface);
wl_surface_destroy(surface);
wl_buffer_destroy(buffer);
wl_buffer_destroy(frontBuffer);
wl_buffer_destroy(backBuffer);
}