Skip to content

Commit

Permalink
Implement surface-invalidated-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
Nefsen402 committed Dec 4, 2022
1 parent a67361e commit ab49f94
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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] == '#') {
Expand All @@ -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
Expand Down Expand Up @@ -74,13 +76,20 @@ struct swaybg_output {
struct wl_surface *surface;
struct zwlr_layer_surface_v1 *layer_surface;


uint32_t width, height;
int32_t scale;

uint32_t configure_serial;
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;
};

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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 =
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]

Expand Down

0 comments on commit ab49f94

Please sign in to comment.