only commit surface when it changed

Previously wvkbd would commit an (usually) unchanged surface at the
framerate of the compositor, this only commits the buffer when we render
something new.

Signed-off-by: Maarten van Gompel <proycon@anaproy.nl>
This commit is contained in:
ArenM 2022-07-05 12:54:33 -04:00 committed by Maarten van Gompel
parent a2cacb7e25
commit 1843e60a74
4 changed files with 8 additions and 24 deletions

18
drw.c
View File

@ -20,30 +20,12 @@ drwsurf_resize(struct drwsurf *ds, uint32_t w, uint32_t h, uint32_t s) {
setup_buffer(ds);
}
static void surface_frame_callback(void *data, struct wl_callback *cb,
uint32_t time);
static struct wl_callback_listener frame_listener = {.done =
surface_frame_callback};
void
drwsurf_flip(struct drwsurf *ds) {
ds->cb = wl_surface_frame(ds->surf);
wl_callback_add_listener(ds->cb, &frame_listener, (void *)ds);
wl_surface_attach(ds->surf, ds->buf, 0, 0);
wl_surface_commit(ds->surf);
}
void
surface_frame_callback(void *data, struct wl_callback *cb, uint32_t time) {
struct drwsurf *ds = (struct drwsurf *)data;
wl_callback_destroy(cb);
ds->cb = NULL;
drwsurf_flip(ds);
}
void
drw_draw_text(struct drwsurf *d, Color color, uint32_t x, uint32_t y,
uint32_t w, uint32_t h, const char *label) {

1
drw.h
View File

@ -15,7 +15,6 @@ struct drwsurf {
struct wl_surface *surf;
struct wl_buffer *buf;
struct wl_shm *shm;
struct wl_callback *cb;
unsigned char *pool_data;
cairo_t *cairo;

View File

@ -207,6 +207,8 @@ kbd_release_key(struct kbd *kb, uint32_t time) {
kbd_draw_layout(kb);
kb->last_swipe = NULL;
}
drwsurf_flip(kb->surf);
}
void
@ -230,6 +232,8 @@ kbd_motion_key(struct kbd *kb, uint32_t time, uint32_t x, uint32_t y) {
} else {
kbd_unpress_key(kb, time);
}
drwsurf_flip(kb->surf);
}
void
@ -336,6 +340,8 @@ kbd_press_key(struct kbd *kb, struct key *k, uint32_t time) {
default:
break;
}
drwsurf_flip(kb->surf);
}
void

7
main.c
View File

@ -341,6 +341,8 @@ layer_surface_configure(void *data, struct zwlr_layer_surface_v1 *surface,
}
zwlr_layer_surface_v1_ack_configure(surface, serial);
drwsurf_flip(&draw_surf);
}
void
@ -376,11 +378,6 @@ hide() {
zwlr_layer_surface_v1_destroy(layer_surface);
wl_surface_destroy(draw_surf.surf);
layer_surface = NULL;
if (draw_surf.cb) {
wl_callback_destroy(draw_surf.cb);
draw_surf.cb = NULL;
}
hidden = true;
}