From 786f8c7b1f39f532483b552bd6ac85f8b5b62beb Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 22 Jan 2021 20:22:09 +0530 Subject: [PATCH] macOS: Ensure font size is correct if the OS moves the newly created window to a different monitor after it is shown --- kitty/glfw.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kitty/glfw.c b/kitty/glfw.c index 2dce3191a..3051de013 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -625,6 +625,16 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { Py_DECREF(pret); if (x != -1 && y != -1) glfwSetWindowPos(glfw_window, x, y); glfwShowWindow(glfw_window); +#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; y_dpi = n_ydpi; + fonts_data = load_fonts_data(global_state.font_sz_in_pts, xdpi, ydpi); + } +#endif } if (is_first_window) { PyObject *ret = PyObject_CallFunction(load_programs, "O", is_semi_transparent ? Py_True : Py_False);