From c6df541783246ea867cd128c74e50afb8c9bf662 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 15 Nov 2022 19:45:28 +0800 Subject: [PATCH] More fixes to last change * lisp/dynamic-setting.el (font-setting-change-default-font): Call `reconsider-frame-fonts'. * src/frame.c (Freconsider_frame_fonts): New function. (syms_of_frame): Add new function. --- lisp/dynamic-setting.el | 11 +++++------ src/frame.c | 28 ++++++++++++++++++++++++++-- src/xfns.c | 8 +++++--- src/xterm.h | 2 +- 4 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lisp/dynamic-setting.el b/lisp/dynamic-setting.el index ff7bf182d1b..ee6d1ceb358 100644 --- a/lisp/dynamic-setting.el +++ b/lisp/dynamic-setting.el @@ -51,12 +51,11 @@ the current form for the frame (i.e. hinting or somesuch changed)." ;; Set the font on all current and future frames, as though ;; the `default' face had been "set for this session": (set-frame-font new-font nil frame-list) - ;; Just redraw the existing fonts on all frames, by clearing - ;; the font and face caches. This will cause all fonts to be - ;; recreated. - (clear-font-cache) - (clear-face-cache t) - (redraw-display))))) + ;; Just reconsider the existing fonts on all frames on each + ;; display, by clearing the font and face caches. This will + ;; cause all fonts to be recreated. + (dolist (frame frame-list) + (reconsider-frame-fonts frame)))))) (defun dynamic-setting-handle-config-changed-event (event) "Handle config-changed-event on the display in EVENT. diff --git a/src/frame.c b/src/frame.c index f076a5ba54e..6eb6f392ecc 100644 --- a/src/frame.c +++ b/src/frame.c @@ -4749,7 +4749,7 @@ gui_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_va if (FRAME_FONT (f)) { /* Reconsider default font after backend(s) change (Bug#23386). */ - FRAME_RIF(f)->default_font_parameter (f, Qnil); + FRAME_RIF (f)->default_font_parameter (f, Qnil); face_change = true; windows_or_buffers_changed = 18; } @@ -5946,6 +5946,30 @@ This function is for internal use only. */) return f->was_invisible ? Qt : Qnil; } + +#ifdef HAVE_WINDOW_SYSTEM + +DEFUN ("reconsider-frame-fonts", Freconsider_frame_fonts, + Sreconsider_frame_fonts, 1, 1, 0, + doc: /* Recreate FRAME's default font using updated font parameters. +Signal an error if FRAME is not a window system frame. This should be +called after a `config-changed' event is received, signalling that the +parameters (such as pixel density) used by the system to open fonts +have changed. */) + (Lisp_Object frame) +{ + struct frame *f; + + f = decode_window_system_frame (frame); + + if (FRAME_RIF (f)->default_font_parameter) + FRAME_RIF (f)->default_font_parameter (f, Qnil); + + return Qnil; +} + +#endif + /*********************************************************************** Multimonitor data @@ -6634,6 +6658,6 @@ iconify the top level frame instead. */); #ifdef HAVE_WINDOW_SYSTEM defsubr (&Sx_get_resource); defsubr (&Sx_parse_geometry); + defsubr (&Sreconsider_frame_fonts); #endif - } diff --git a/src/xfns.c b/src/xfns.c index 3ff7a8c2865..6bd613ba692 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -4506,9 +4506,11 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms) } if (NILP (font)) - font = !NILP (font_param) ? font_param - : gui_display_get_arg (dpyinfo, parms, Qfont, "font", "Font", - RES_TYPE_STRING); + font = (!NILP (font_param) + ? font_param + : gui_display_get_arg (dpyinfo, parms, + Qfont, "font", "Font", + RES_TYPE_STRING)); if (! FONTP (font) && ! STRINGP (font)) { diff --git a/src/xterm.h b/src/xterm.h index 1124dcceb4a..b6ab42e72d2 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -1615,7 +1615,7 @@ extern void x_real_pos_and_offsets (struct frame *f, int *xptr, int *yptr, int *outer_border); -extern void x_default_font_parameter (struct frame* f, Lisp_Object parms); +extern void x_default_font_parameter (struct frame *, Lisp_Object); /* From xrdb.c. */ -- 2.39.5