From 353a56dbbfc59da573b4afacd159433ea57b9612 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 12 Apr 2024 08:29:53 +0530 Subject: [PATCH] Wayland: Fix initial font size wrong when using fractional scales We have to check for window scale after window is shown as Wayland has this crazy design where the compositor only sets fractional scale after the window is shown. Which means kitty has to do useless work calculating font metrics twice. Sigh. --- kitty/glfw.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/kitty/glfw.c b/kitty/glfw.c index 22e1c9c85..bab1597b4 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1208,19 +1208,21 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) { if (pret == NULL) return NULL; Py_DECREF(pret); if (x != INT_MIN && y != INT_MIN) glfwSetWindowPos(glfw_window, x, y); + bool is_apple = true; #ifndef __APPLE__ + is_apple = false; glfwShowWindow(glfw_window); #endif -#ifdef __APPLE__ - float n_xscale, n_yscale; - double n_xdpi, n_ydpi; - get_window_content_scale(glfw_window, &n_xscale, &n_yscale, &n_xdpi, &n_ydpi); - if (n_xdpi != xdpi || n_ydpi != ydpi) { - // this can happen if the window is moved by the OS to a different monitor when shown - xdpi = n_xdpi; ydpi = n_ydpi; - fonts_data = load_fonts_data(OPT(font_size), xdpi, ydpi); + if (global_state.is_wayland || is_apple) { + float n_xscale, n_yscale; + double n_xdpi, n_ydpi; + get_window_content_scale(glfw_window, &n_xscale, &n_yscale, &n_xdpi, &n_ydpi); + if (n_xdpi != xdpi || n_ydpi != ydpi) { + // this can happen if the window is moved by the OS to a different monitor when shown or with fractional scales on Wayland + xdpi = n_xdpi; ydpi = n_ydpi; + fonts_data = load_fonts_data(OPT(font_size), xdpi, ydpi); + } } -#endif if (is_first_window) { PyObject *ret = PyObject_CallFunction(load_programs, "O", is_semi_transparent ? Py_True : Py_False); if (ret == NULL) return NULL;