From ab49f9453ceaa1073f97b529125ee2d6d95c226a Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Sun, 4 Dec 2022 15:59:22 -0500 Subject: [PATCH] Implement surface-invalidated-v1 --- main.c | 43 +++++++++++++++++++++++++++++++++++++++++++ meson.build | 1 + 2 files changed, 44 insertions(+) diff --git a/main.c b/main.c index dce5b5a..70cbfe4 100644 --- a/main.c +++ b/main.c @@ -15,6 +15,7 @@ #include "wlr-layer-shell-unstable-v1-client-protocol.h" #include "viewporter-client-protocol.h" #include "single-pixel-buffer-v1-client-protocol.h" +#include "surface-invalidation-v1-client-protocol.h" static uint32_t parse_color(const char *color) { if (color[0] == '#') { @@ -41,6 +42,7 @@ struct swaybg_state { struct zwlr_layer_shell_v1 *layer_shell; struct wp_viewporter *viewporter; struct wp_single_pixel_buffer_manager_v1 *single_pixel_buffer_manager; + struct wp_surface_invalidation_manager_v1 *surface_invalidation_manager; struct wl_list configs; // struct swaybg_output_config::link struct wl_list outputs; // struct swaybg_output::link struct wl_list images; // struct swaybg_image::link @@ -74,6 +76,7 @@ struct swaybg_output { struct wl_surface *surface; struct zwlr_layer_surface_v1 *layer_surface; + uint32_t width, height; int32_t scale; @@ -81,6 +84,12 @@ struct swaybg_output { bool dirty, needs_ack; int32_t committed_width, committed_height, committed_scale; + struct { + struct wp_surface_invalidation_v1 *protocol; + bool needs_ack; + uint32_t serial; + } surface_invalidation; + struct wl_list link; }; @@ -255,10 +264,31 @@ static void output_mode(void *data, struct wl_output *output, uint32_t flags, // Who cares } +static void surface_invalidation_handle_invalidated(void *data, + struct wp_surface_invalidation_v1 *wp_surface_invalidation_v1, uint32_t serial) { + struct swaybg_output *output = data; + + output->dirty = true; + output->surface_invalidation.needs_ack = true; + output->surface_invalidation.serial = serial; +} + +static struct wp_surface_invalidation_v1_listener surface_invalidation_listener = { + .invalidated = surface_invalidation_handle_invalidated, +}; + static void create_layer_surface(struct swaybg_output *output) { output->surface = wl_compositor_create_surface(output->state->compositor); assert(output->surface); + if (output->state->surface_invalidation_manager) { + output->surface_invalidation.protocol = + wp_surface_invalidation_manager_v1_get_surface_invalidation( + output->state->surface_invalidation_manager, output->surface); + wp_surface_invalidation_v1_add_listener(output->surface_invalidation.protocol, + &surface_invalidation_listener, output); + } + // Empty input region struct wl_region *input_region = wl_compositor_create_region(output->state->compositor); @@ -385,6 +415,10 @@ static void handle_global(void *data, struct wl_registry *registry, wp_single_pixel_buffer_manager_v1_interface.name) == 0) { state->single_pixel_buffer_manager = wl_registry_bind(registry, name, &wp_single_pixel_buffer_manager_v1_interface, 1); + } else if (strcmp(interface, + wp_surface_invalidation_manager_v1_interface.name) == 0) { + state->surface_invalidation_manager = wl_registry_bind(registry, name, + &wp_surface_invalidation_manager_v1_interface, 1); } } @@ -600,6 +634,15 @@ int main(int argc, char **argv) { output->configure_serial); } + if (output->surface_invalidation.needs_ack) { + output->surface_invalidation.needs_ack = false; + wp_surface_invalidation_v1_ack(output->surface_invalidation.protocol, + output->surface_invalidation.serial); + output->committed_width = 0; + output->committed_height = 0; + output->committed_scale = 0; + } + int buffer_width = output->width * output->scale, buffer_height = output->height * output->scale; bool buffer_change = diff --git a/meson.build b/meson.build index 7467805..dc53736 100644 --- a/meson.build +++ b/meson.build @@ -74,6 +74,7 @@ client_protocols = [ wl_protocol_dir / 'stable/xdg-shell/xdg-shell.xml', wl_protocol_dir / 'stable/viewporter/viewporter.xml', wl_protocol_dir / 'staging/single-pixel-buffer/single-pixel-buffer-v1.xml', + wl_protocol_dir / 'staging/surface-invalidation/surface-invalidation-v1.xml', 'wlr-layer-shell-unstable-v1.xml', ]