about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArenM <aren@peacevolution.org>2022-07-05 12:54:33 -0400
committerZach DeCook <zachdecook@librem.one>2022-07-11 00:59:10 -0400
commit6566a7f57d695d888650d43225844f9641414919 (patch)
treebd41dae2b3add5810e7b2dbf146667a5e402f0d9
parent1c4df6ae2b9c94feb6b65e616520275b645bfa5c (diff)
downloadsuggpicker-6566a7f57d695d888650d43225844f9641414919.tar.gz
only commit surface when it changed
This is based off of a commit in wvkbd

Previously wvkbd (and suggpicker) would commit a (usually unchanged) surface at the framerate of the compositor,
this only commits the buffer when we render something new.
-rw-r--r--drw.c18
-rw-r--r--drw.h1
-rw-r--r--keyboard.c3
-rw-r--r--main.c13
4 files changed, 8 insertions, 27 deletions
diff --git a/drw.c b/drw.c
index a7cfd20..6ea904e 100644
--- a/drw.c
+++ b/drw.c
@@ -20,31 +20,13 @@ 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) {
 
diff --git a/drw.h b/drw.h
index fb3df1c..c1139f4 100644
--- a/drw.h
+++ b/drw.h
@@ -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;
diff --git a/keyboard.c b/keyboard.c
index 2b1506a..293a2f6 100644
--- a/keyboard.c
+++ b/keyboard.c
@@ -73,6 +73,7 @@ kbd_unpress_key(struct kbd *kb) {
 	if (kb->last_press) {
 		kbd_draw_key(kb, kb->last_press, Unpress);
 		kb->last_press = NULL;
+		drwsurf_flip(kb->surf);
 	}
 }
 
@@ -83,7 +84,6 @@ kbd_release_key(struct kbd *kb) {
 		// Important so autocompleted words get typed in time
 		fflush(stdout);
 		kbd_unpress_key(kb);
-		kbd_draw_layout(kb);
 	}
 }
 
@@ -104,6 +104,7 @@ kbd_press_key(struct kbd *kb, struct key *k) {
 	if (k->label) {
 		kb->last_press = k;
 		kbd_draw_key(kb, k, Press);
+		drwsurf_flip(kb->surf);
 	}
 }
 
diff --git a/main.c b/main.c
index 311c4e9..563baae 100644
--- a/main.c
+++ b/main.c
@@ -307,6 +307,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
@@ -339,10 +341,6 @@ hide(int sigint) {
 	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;
-	}
 }
 
 void
@@ -399,6 +397,7 @@ handle_input(FILE *fd, struct key *sugg, struct kbd *kb) {
 		key->label = NULL;
 		kbd_init_suggs(sugg, kb->w, kb->h);
 		kbd_draw_layout(kb);
+		drwsurf_flip(kb->surf);
 	}
 
 	free(line);
@@ -506,9 +505,9 @@ main(int argc, char **argv) {
 		while(layer_surface && poll(fds, 2, -1) != -1) {
 			if (fds[0].revents & POLLIN) {
 				handle_input(stdin, keyboard.suggs, &keyboard);
-			}
-			if (wl_display_dispatch(display) == -1) {
-				break;
+			} else if(fds[1].revents & POLLIN) {
+				//error check?
+				wl_display_dispatch(display);
 			}
 			wl_display_flush(display);
 		}