diff options
-rw-r--r-- | src/entry.c | 19 | ||||
-rw-r--r-- | src/entry_backend/harfbuzz.c | 8 | ||||
-rw-r--r-- | src/entry_backend/pango.c | 9 | ||||
-rw-r--r-- | src/main.c | 4 |
4 files changed, 31 insertions, 9 deletions
diff --git a/src/entry.c b/src/entry.c index 133a706..d387f2c 100644 --- a/src/entry.c +++ b/src/entry.c @@ -132,6 +132,20 @@ void entry_init(struct entry *entry, uint8_t *restrict buffer, uint32_t width, u } /* + * Perform an initial render of the text. + * This is done here rather than by calling entry_update to avoid the + * unnecessary cairo_paint() of the background for the first frame, + * which can be slow for large (e.g. fullscreen) windows. + */ + log_debug("Initial text render.\n"); + if (entry->use_pango) { + entry_backend_pango_update(entry); + } else { + entry_backend_harfbuzz_update(entry); + } + entry->index = !entry->index; + + /* * To avoid performing all this drawing twice, we take a small * shortcut. After performing all the drawing as normal on our first * Cairo context, we can copy over just the important state (the @@ -169,7 +183,6 @@ void entry_update(struct entry *entry) { log_debug("Start rendering entry.\n"); cairo_t *cr = entry->cairo[entry->index].cr; - cairo_save(cr); /* Clear the image. */ struct color color = entry->background_color; @@ -180,16 +193,12 @@ void entry_update(struct entry *entry) cairo_restore(cr); /* Draw our text. */ - color = entry->foreground_color; - cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); - if (entry->use_pango) { entry_backend_pango_update(entry); } else { entry_backend_harfbuzz_update(entry); } - cairo_restore(cr); log_debug("Finish rendering entry.\n"); entry->index = !entry->index; diff --git a/src/entry_backend/harfbuzz.c b/src/entry_backend/harfbuzz.c index ed15e82..f0a04e0 100644 --- a/src/entry_backend/harfbuzz.c +++ b/src/entry_backend/harfbuzz.c @@ -196,6 +196,10 @@ void entry_backend_harfbuzz_update(struct entry *entry) hb_buffer_t *buffer = entry->harfbuzz.hb_buffer; uint32_t width; + cairo_save(cr); + struct color color = entry->foreground_color; + cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); + /* Render the entry text */ hb_buffer_clear_contents(buffer); setup_hb_buffer(buffer); @@ -221,7 +225,7 @@ void entry_backend_harfbuzz_update(struct entry *entry) hb_shape(entry->harfbuzz.hb_font, buffer, NULL, 0); if (i == entry->selection) { cairo_save(cr); - struct color color = entry->selection_color; + color = entry->selection_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); } width = render_hb_buffer(cr, buffer); @@ -229,4 +233,6 @@ void entry_backend_harfbuzz_update(struct entry *entry) cairo_restore(cr); } } + + cairo_restore(cr); } diff --git a/src/entry_backend/pango.c b/src/entry_backend/pango.c index cc2a361..6c2399a 100644 --- a/src/entry_backend/pango.c +++ b/src/entry_backend/pango.c @@ -59,6 +59,11 @@ void entry_backend_pango_update(struct entry *entry) cairo_t *cr = entry->cairo[entry->index].cr; PangoLayout *layout = entry->pango.layout; + cairo_save(cr); + struct color color = entry->foreground_color; + cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); + + pango_layout_set_text(layout, entry->input_mb, -1); pango_cairo_update_layout(cr, layout); pango_cairo_show_layout(cr, layout); @@ -84,7 +89,7 @@ void entry_backend_pango_update(struct entry *entry) pango_cairo_update_layout(cr, layout); if (i == entry->selection) { cairo_save(cr); - struct color color = entry->selection_color; + color = entry->selection_color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); } pango_cairo_show_layout(cr, layout); @@ -93,4 +98,6 @@ void entry_backend_pango_update(struct entry *entry) } pango_layout_get_size(layout, &width, &height); } + + cairo_restore(cr); } @@ -90,6 +90,7 @@ static void wl_keyboard_keymap( { struct tofi *tofi = data; assert(format == WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1); + log_debug("Configuring keyboard.\n"); char *map_shm = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); assert(map_shm != MAP_FAILED); @@ -557,7 +558,7 @@ static const struct wl_surface_listener wl_surface_listener = { static void usage() { - fprintf(stderr, + fprintf(stderr, "%s", "Usage: tofi [options]\n" " -h, --help Print this message and exit.\n" " -c, --config Specify a config file.\n" @@ -891,7 +892,6 @@ int main(int argc, char *argv[]) tofi.window.surface.shm_pool_data, tofi.window.width, tofi.window.height); - entry_update(&tofi.window.entry); log_unindent(); log_debug("Renderer initialised.\n"); |