diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-04-24 11:37:22 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2023-04-24 11:37:22 +0200 |
| commit | feb5adefd9d4909aa30d3a49e173a8954b755de2 (patch) | |
| tree | 8e457891824d08386f24eee6e3915f3a8b28d0ee | |
| parent | 67893dc14d10f49a76652ff384ab2bf4a945ca30 (diff) | |
fix fontcache, free glyph after drawing if not cached
| -rw-r--r-- | config.h | 2 | ||||
| -rw-r--r-- | drw.c | 29 | ||||
| -rw-r--r-- | swt.c | 16 |
3 files changed, 33 insertions, 14 deletions
@@ -180,6 +180,8 @@ static unsigned int mousefg = 7; static unsigned int mousebg = 0; */ +static unsigned int scrollstep = 15; + /* * Color used to display font attributes when fontconfig selected a font which * doesn't match the ones requested. @@ -13,6 +13,11 @@ extern int boldstokemode; +typedef struct { + FT_Glyph glyph; + FT_BitmapGlyph bg; +} CacheGlyph; + /* static function declarations */ static Color to_color(uint32_t color); static uint32_t to_uint32_t(Color color); @@ -380,9 +385,10 @@ get_font_with_charcode(FontCache *fontcache, uint_least32_t charcode) } -FT_BitmapGlyph +CacheGlyph load_bitmap(Font *font, uint_least32_t charcode) { + CacheGlyph cglyph = { .bg = 0, .glyph = 0 }; FT_Bool has_kerning; FT_Vector delta; FT_UInt glyph_index; @@ -403,21 +409,21 @@ load_bitmap(Font *font, uint_least32_t charcode) error = FT_Load_Glyph(font->face, glyph_index, FT_LOAD_DEFAULT); if (error) { fprintf(stderr, "warning: char not loaded, skipping...\n"); - return 0; + return cglyph; } FT_Get_Glyph(slot, &glyph); FT_Glyph_StrokeBorder(&glyph, font->stroke, 0, 1); if (error) { fprintf(stderr, "warning: could not apply stroke\n"); - return 0; + return cglyph; } FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 1); bg = (FT_BitmapGlyph)glyph; if (glyph_index >= CACHE_SIZE) { - FT_Done_Glyph(glyph); + cglyph.glyph = glyph; } else { font->cache[glyph_index] = bg; } @@ -425,14 +431,16 @@ load_bitmap(Font *font, uint_least32_t charcode) bg = font->cache[glyph_index]; } - return bg; + cglyph.bg = bg; + + return cglyph; } void draw_char(Canvas *canvas, FontCache *fontcache, uint_least32_t charcode, unsigned x, unsigned y, uint32_t color) { Font *font; - FT_BitmapGlyph bg; + CacheGlyph cg; font = get_font_with_charcode(fontcache, charcode); FT_Set_Pixel_Sizes(font->face, 0, fontcache->fontsize); @@ -444,11 +452,14 @@ draw_char(Canvas *canvas, FontCache *fontcache, uint_least32_t charcode, unsigne FT_Stroker_Set(font->stroke, 0, FT_STROKER_LINECAP_BUTT, FT_STROKER_LINEJOIN_ROUND, 0); } - bg = load_bitmap(font, charcode); + cg = load_bitmap(font, charcode); - if (bg == 0) + if (cg.bg == 0) return; - draw_bitmap(canvas, &bg->bitmap, x + bg->left, y - bg->top, color); + draw_bitmap(canvas, &cg.bg->bitmap, x + cg.bg->left, y - cg.bg->top, color); + + if (cg.glyph) + FT_Done_Glyph(cg.glyph); } @@ -784,11 +784,15 @@ pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t client.pointer.buttons.tclick = time; ++client.pointer.buttons.click_combo; - selstart( - MIN(wintotty(client.pointer.position.x, width), win.tty.width - 1), - MIN(wintotty(client.pointer.position.y, height), win.tty.height - 1), - snap - ); + if (IS_SET(MODE_MOUSE) | IS_SET(MODE_MOUSEMANY) | IS_SET(MODE_MOUSEBTN)) { + ttywrite("\031", 1, 1); + } else { + selstart( + MIN(wintotty(client.pointer.position.x, width), win.tty.width - 1), + MIN(wintotty(client.pointer.position.y, height), win.tty.height - 1), + snap + ); + } win.redraw = 1; } else if (button == BTN_LEFT && !state) { client.pointer.buttons.button &= ~BTN_LEFT; @@ -805,6 +809,8 @@ pointer_button(void *data, struct wl_pointer *pointer, uint32_t serial, uint32_t void pointer_axis(void *data, struct wl_pointer *pointer, uint32_t time, uint32_t axis, wl_fixed_t value) { + int v = wl_fixed_to_int(value); + fprintf(stderr, "scroll: a: %i, v: %i\n", axis, v); } |