From 0b9a244a12b6e529eae0e41ec52e7614206e4ae5 Mon Sep 17 00:00:00 2001 From: Igor Kolokolnikov Date: Thu, 8 Oct 2026 22:26:30 -0700 Subject: [PATCH] Improve font rendering. --- Makefile | 2 +- slock.c | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 50ef0b5..2ed553b 100644 --- a/Makefile +++ b/Makefile @@ -56,7 +56,7 @@ ifeq ($(OS),OS_MACOS) LIBS = FRAMEWORKS = else ifeq ($(OS),OS_LINUX) - # FLAGS = -ggdb -DDEBUG=1 -DINTERNAL=1 + # FLAGS = -ggdb3 -O0 -DDEBUG=1 -DINTERNAL=1 FLAGS = -O3 INCLUDE = -I/usr/include -I/usr/X11R6/include \ -I./libs/include/freetype2 diff --git a/slock.c b/slock.c index 3b443dd..8fff875 100644 --- a/slock.c +++ b/slock.c @@ -361,7 +361,6 @@ draw_glyph(void *memory, int width, int height, int bytes_per_pixel, bitmap_width = face->glyph->bitmap.width; bitmap_rows = face->glyph->bitmap.rows; bitmap_pixels = (void *)face->glyph->bitmap.buffer; - y -= face->glyph->bitmap_top; row = 0; column = 0; @@ -452,9 +451,12 @@ draw_string(void *buffer, int width, int height, break; } - draw_glyph(buffer, width, height, 4, face, start_x, start_y); + draw_glyph(buffer, + width, height, 4, face, + start_x + face->glyph->bitmap_left, + start_y - face->glyph->bitmap_top); - start_x += face->glyph->bitmap.width; + start_x += (face->glyph->advance.x + 32) >> 6; } } } @@ -488,7 +490,7 @@ get_string_dimension(int *width, int *height, const char *str, FT_Face face) break; } - result_width += face->glyph->bitmap.width; + result_width += (face->glyph->advance.x + 32) >> 6; if(face->glyph->bitmap.rows > (unsigned int)result_height) result_height = face->glyph->bitmap.rows; } @@ -544,13 +546,21 @@ render_screen(struct arena *arena, time_str = (char *)arena_alloc(&temp_arena, time_str_len); get_time_str(time_str, time_str_len); if(FT_Set_Pixel_Sizes(main_font_face, 0, 200) == 0) { + int pos_x, pos_y; + int mwidth, mheight; get_string_dimension(&mwidth, &mheight, time_str, main_font_face); + + pos_x = width/2-mwidth/2; + if(pass_len > 0 || failure) + pos_y = height/4+mheight/2; + else + pos_y = height/2+mheight/2; draw_string(data, width, height, time_str, main_font_face, - width/2-mwidth/2, height/4+mheight/2); + pos_x, pos_y); } if(FT_Set_Pixel_Sizes(secondary_font_face, 0, 30) == 0) { @@ -564,7 +574,7 @@ render_screen(struct arena *arena, if(locked && failure) memcpy(message_str, "wrong password", 15); else if(locked) - memcpy(message_str, "locked", 7); + /*memcpy(message_str, "locked", 7);*/ if(pass_len > 0) { unsigned int i; @@ -612,9 +622,10 @@ static void dpms_disable(Display *dpy, struct dpms_state *state) &state->dpmsoff)) { state->dpmsavailable = 1; - if(state->dpmsstate) + if(state->dpmsstate) { DPMSDisable(dpy); - XSync(dpy, 0); + XSync(dpy, 0); + } } } @@ -1003,6 +1014,19 @@ lockscreen(Display *dpy, struct xrandr *rr, int screen) DefaultVisual(dpy, lock->screen), CWOverrideRedirect | CWBackPixel, &wa); #endif + + /*XStoreName(dpy, lock->win, "Title");*/ + +#if DEBUG + { + XClassHint hint; + hint.res_name = "testing_full"; + hint.res_class = "testing_class"; + + XSetClassHint(dpy, lock->win, &hint); + XSync(dpy, 0); + } +#endif XSetWindowBackground(dpy, lock->win, BlackPixel(dpy, screen)); XClearWindow(dpy, lock->win);