From fbcdf352acd3942fe55bcfa4fe1e7f48a5835ce6 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 14 Feb 2021 22:17:41 +0530 Subject: [PATCH] Allow resizing of OS Window framebuffers to a single cell This is much smaller than before and essentially works around the issue of the text being scaled when the window is resized to small sizes. Also has the nice side effect of making the code simpler for the panel kitten. Fixes #3307 --- docs/changelog.rst | 2 ++ kittens/panel/main.py | 8 +++----- kitty/fast_data_types.pyi | 4 ---- kitty/glfw.c | 18 +++++++++--------- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index ce308ab9e..52c523891 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -62,6 +62,8 @@ To update |kitty|, :doc:`follow the instructions `. - Fix window icon not working on X11 with 64bits (:iss:`3260`) +- Fix OS window sizes under 100px resulting in scaled display (:iss:`3307`) + 0.19.3 [2020-12-19] ------------------- diff --git a/kittens/panel/main.py b/kittens/panel/main.py index 559550aff..7f22e797a 100644 --- a/kittens/panel/main.py +++ b/kittens/panel/main.py @@ -121,19 +121,17 @@ def setup_x11_window(win_id: int) -> None: def initial_window_size_func(opts: WindowSizeData, cached_values: Dict) -> Callable[[int, int, float, float, float, float], Tuple[int, int]]: - from kitty.fast_data_types import glfw_primary_monitor_size, set_smallest_allowed_resize + from kitty.fast_data_types import glfw_primary_monitor_size def initial_window_size(cell_width: int, cell_height: int, dpi_x: float, dpi_y: float, xscale: float, yscale: float) -> Tuple[int, int]: global window_width, window_height monitor_width, monitor_height = glfw_primary_monitor_size() if args.edge in {'top', 'bottom'}: - h = window_height = cell_height * args.lines + 1 + window_height = cell_height * args.lines + 1 window_width = monitor_width - set_smallest_allowed_resize(100, h) else: - w = window_width = cell_width * args.columns + 1 + window_width = cell_width * args.columns + 1 window_height = monitor_height - set_smallest_allowed_resize(w, 100) return window_width, window_height return initial_window_size diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 743cb2454..5b69a9ecb 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -521,10 +521,6 @@ def glfw_primary_monitor_size() -> Tuple[int, int]: pass -def set_smallest_allowed_resize(width: int, height: int) -> None: - pass - - def set_default_window_icon(path: str) -> None: pass diff --git a/kitty/glfw.c b/kitty/glfw.c index 055dfe307..12e34027d 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -33,7 +33,12 @@ request_tick_callback(void) { glfwPostEmptyEvent(); } -static int min_width = 100, min_height = 100; +static inline void +min_size_for_os_window(OSWindow *window, int *min_width, int *min_height) { + *min_width = MAX(8u, window->fonts_data->cell_width + 1); + *min_height = MAX(8u, window->fonts_data->cell_height + 1); +} + void update_os_window_viewport(OSWindow *window, bool notify_boss) { @@ -46,7 +51,8 @@ update_os_window_viewport(OSWindow *window, bool notify_boss) { if (fw == window->viewport_width && fh == window->viewport_height && w == window->window_width && h == window->window_height && xdpi == window->logical_dpi_x && ydpi == window->logical_dpi_y) { return; // no change, ignore } - if (w <= 0 || h <= 0 || fw / w > 5 || fh / h > 5 || fw < min_width || fh < min_height || fw < w || fh < h) { + int min_width, min_height; min_size_for_os_window(window, &min_width, &min_height); + if (w <= 0 || h <= 0 || fw < min_width || fh < min_height || fw < w || fh < h) { log_error("Invalid geometry ignored: framebuffer: %dx%d window: %dx%d\n", fw, fh, w, h); if (!window->viewport_updated_at_least_once) { window->viewport_width = min_width; window->viewport_height = min_height; @@ -191,6 +197,7 @@ live_resize_callback(GLFWwindow *w, bool started) { static void framebuffer_size_callback(GLFWwindow *w, int width, int height) { if (!set_callback_window(w)) return; + int min_width, min_height; min_size_for_os_window(global_state.callback_os_window, &min_width, &min_height); if (width >= min_width && height >= min_height) { OSWindow *window = global_state.callback_os_window; global_state.has_pending_resizes = true; @@ -1202,12 +1209,6 @@ set_primary_selection(PyObject UNUSED *self, PyObject *args) { Py_RETURN_NONE; } -static PyObject* -set_smallest_allowed_resize(PyObject *self UNUSED, PyObject *args) { - if (!PyArg_ParseTuple(args, "ii", &min_width, &min_height)) return NULL; - Py_RETURN_NONE; -} - static PyObject* set_custom_cursor(PyObject *self UNUSED, PyObject *args) { int shape; @@ -1345,7 +1346,6 @@ stop_main_loop(void) { static PyMethodDef module_methods[] = { METHODB(set_custom_cursor, METH_VARARGS), - METHODB(set_smallest_allowed_resize, METH_VARARGS), METHODB(create_os_window, METH_VARARGS), METHODB(set_default_window_icon, METH_VARARGS), METHODB(get_clipboard_string, METH_NOARGS),