>From 100ed84198cd97664a94e89d1730e97b1fabbbb9 Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Fri, 14 Oct 2022 16:24:10 +0200 Subject: [PATCH] Fix menu bar height for --with-x-toolkit=no * src/xterm.c (x_menu_bar_height): New function to compute menu bar height with menu face and boxed information. (x_new_font): Use it. * src/xfns.c (x_set_menu_bar_lines): Use it. --- src/xfns.c | 2 +- src/xterm.c | 25 ++++++++++++++++++++++++- src/xterm.h | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/xfns.c b/src/xfns.c index 9112448899..3d93a6a207 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -1674,7 +1674,7 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval) } #else /* not USE_X_TOOLKIT && not USE_GTK */ FRAME_MENU_BAR_LINES (f) = nlines; - FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f); + FRAME_MENU_BAR_HEIGHT (f) = nlines * x_menu_bar_height (f); if (FRAME_X_WINDOW (f)) x_clear_under_internal_border (f); diff --git a/src/xterm.c b/src/xterm.c index 9059ad7136..c3bc494667 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -25464,6 +25464,29 @@ x_io_error_quitter (Display *display) /* Changing the font of the frame. */ +int +x_menu_bar_height (struct frame *f) +{ + int font_ascent = 0; + int font_descent = 0; + int height = 0; + + recompute_basic_faces (f); + if (FRAME_FACE_CACHE (f)) + { + struct face *face = FACE_FROM_ID_OR_NULL (f, MENU_FACE_ID); + if (face && face->font) + { + height += (face->box_horizontal_line_width > 0) + ? (face->box_horizontal_line_width * 2) + : 0; + get_font_ascent_descent (face->font, &font_ascent, &font_descent); + } + } + + return (height + font_ascent + font_descent); +} + /* Give frame F the font FONT-OBJECT as its default font. The return value is FONT-OBJECT. FONTSET is an ID of the fontset for the frame. If it is negative, generate a new fontset from @@ -25490,7 +25513,7 @@ x_new_font (struct frame *f, Lisp_Object font_object, int fontset) FRAME_LINE_HEIGHT (f) = font_ascent + font_descent; #ifndef USE_X_TOOLKIT - FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f); + FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * x_menu_bar_height (f); #endif /* We could use a more elaborate calculation here. */ FRAME_TAB_BAR_HEIGHT (f) = FRAME_TAB_BAR_LINES (f) * FRAME_LINE_HEIGHT (f); diff --git a/src/xterm.h b/src/xterm.h index b68a234faa..5b914d48da 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -1595,6 +1595,7 @@ #define SELECTION_EVENT_TIME(eventp) \ extern void x_ignore_errors_for_next_request (struct x_display_info *); extern void x_stop_ignoring_errors (struct x_display_info *); extern void x_clear_errors (Display *); +extern int x_menu_bar_height (struct frame *); extern void x_set_window_size (struct frame *, bool, int, int); extern void x_set_last_user_time_from_lisp (struct x_display_info *, Time); extern void x_make_frame_visible (struct frame *); -- 2.38.0