summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Stoeckl <code@mstoeckl.com>2021-05-17 18:30:34 -0400
committerSimon Ser <contact@emersion.fr>2021-06-22 20:07:56 +0200
commitccbd046b3347734d98d49ce3272f54187148b5a7 (patch)
treeb5daa1bef04c2340e55b91d231a7682fa73a2608
parent3cb81c3573036a3606a4c7a1cedbe3e814a22773 (diff)
downloadswaybg-ccbd046b3347734d98d49ce3272f54187148b5a7.tar.gz
swaybg-ccbd046b3347734d98d49ce3272f54187148b5a7.tar.bz2
React only to most recent configure event
When outputs are dynamically resized, as can happen when sway is run nested with its wayland or x11 backend, layer shell programs receive a stream of configure events. In such cases, only rendering a frame for the last configure event avoids wasted computation.
Diffstat (limited to '')
-rw-r--r--main.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/main.c b/main.c
index c03c27a..ce8edc8 100644
--- a/main.c
+++ b/main.c
@@ -70,6 +70,9 @@ struct swaybg_output {
uint32_t width, height;
int32_t scale;
+ uint32_t configure_serial;
+ bool dirty, needs_ack;
+
struct wl_list link;
};
@@ -157,8 +160,9 @@ static void layer_surface_configure(void *data,
struct swaybg_output *output = data;
output->width = width;
output->height = height;
- zwlr_layer_surface_v1_ack_configure(surface, serial);
- render_frame(output);
+ output->dirty = true;
+ output->configure_serial = serial;
+ output->needs_ack = true;
}
static void layer_surface_closed(void *data,
@@ -194,7 +198,7 @@ static void output_scale(void *data, struct wl_output *wl_output,
struct swaybg_output *output = data;
output->scale = scale;
if (output->state->run_display && output->width > 0 && output->height > 0) {
- render_frame(output);
+ output->dirty = true;
}
}
@@ -532,7 +536,18 @@ int main(int argc, char **argv) {
state.run_display = true;
while (wl_display_dispatch(state.display) != -1 && state.run_display) {
- // This space intentionally left blank
+ wl_list_for_each(output, &state.outputs, link) {
+ if (output->needs_ack) {
+ output->needs_ack = false;
+ zwlr_layer_surface_v1_ack_configure(
+ output->layer_surface,
+ output->configure_serial);
+ }
+ if (output->dirty) {
+ output->dirty = false;
+ render_frame(output);
+ }
+ }
}
struct swaybg_output *tmp_output;