prevent unnecessary redraws in layer_surface_configure

This commit is contained in:
kolunmi 2023-02-15 10:46:23 -07:00
parent f3527b5599
commit 26603abf13

18
dwlb.c
View File

@ -93,6 +93,7 @@ struct Bar {
uint32_t registry_name; uint32_t registry_name;
char *xdg_output_name; char *xdg_output_name;
bool configured;
uint32_t width; uint32_t width;
uint32_t height; uint32_t height;
uint32_t textpadding; uint32_t textpadding;
@ -131,7 +132,6 @@ static struct fcft_font *font;
static Bar *bars = NULL; static Bar *bars = NULL;
// TODO: it would be nice to have these be configurable, currently set by font
static uint32_t height; static uint32_t height;
static uint32_t textpadding; static uint32_t textpadding;
@ -461,15 +461,18 @@ static void
layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface, layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
uint32_t serial, uint32_t w, uint32_t h) uint32_t serial, uint32_t w, uint32_t h)
{ {
zwlr_layer_surface_v1_ack_configure(surface, serial);
Bar *b = (Bar *)data; Bar *b = (Bar *)data;
if (b->configured && w == b->width && h == b->height)
return;
b->width = w; b->width = w;
b->height = h; b->height = h;
b->stride = b->width * 4; b->stride = b->width * 4;
b->bufsize = b->stride * b->height; b->bufsize = b->stride * b->height;
b->configured = true;
zwlr_layer_surface_v1_set_exclusive_zone(b->layer_surface, b->height);
zwlr_layer_surface_v1_ack_configure(surface, serial);
draw_frame(b); draw_frame(b);
} }
@ -477,10 +480,6 @@ layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
static void static void
layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface) layer_surface_closed(void *data, struct zwlr_layer_surface_v1 *surface)
{ {
Bar *b = (Bar *)data;
zwlr_layer_surface_v1_destroy(surface);
wl_surface_destroy(b->wl_surface);
run_display = false; run_display = false;
} }
@ -557,6 +556,7 @@ show_bar(Bar *b)
(b->bottom ? ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM : ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP) (b->bottom ? ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM : ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP)
| ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT
| ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT); | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT);
zwlr_layer_surface_v1_set_exclusive_zone(b->layer_surface, b->height);
wl_surface_commit(b->wl_surface); wl_surface_commit(b->wl_surface);
b->hidden = false; b->hidden = false;
@ -567,6 +567,8 @@ hide_bar(Bar *b)
{ {
zwlr_layer_surface_v1_destroy(b->layer_surface); zwlr_layer_surface_v1_destroy(b->layer_surface);
wl_surface_destroy(b->wl_surface); wl_surface_destroy(b->wl_surface);
b->configured = false;
b->hidden = true; b->hidden = true;
} }