Resize OS panels on font size change

This commit is contained in:
Kovid Goyal 2025-04-23 07:11:39 +05:30
parent ae01cf3c1c
commit 3c4a8a1e7e
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
5 changed files with 36 additions and 24 deletions

View file

@ -1929,9 +1929,10 @@ bool
_glfwPlatformSetLayerShellConfig(_GLFWwindow* window, const GLFWLayerShellConfig *value) {
#define config window->ns.layer_shell.config
window->resizable = false;
if (value) config = *value;
const bool is_transparent = ![window->ns.object isOpaque];
int background_blur = value->related.background_blur;
if (!is_transparent || value->related.background_opacity >= 1.f) { background_blur = 0; }
int background_blur = config.related.background_blur;
if (!is_transparent || config.related.background_opacity >= 1.f) { background_blur = 0; }
[window->ns.object setBackgroundColor:nil];
_glfwPlatformSetWindowBlur(window, background_blur);
window->ns.titlebar_hidden = true;
@ -1940,7 +1941,7 @@ _glfwPlatformSetLayerShellConfig(_GLFWwindow* window, const GLFWLayerShellConfig
[window->ns.object setHasShadow:false];
[window->ns.object setTitleVisibility:NSWindowTitleHidden];
NSColorSpace *cs = nil;
switch (value->related.color_space) {
switch (config.related.color_space) {
case SRGB_COLORSPACE: cs = [NSColorSpace sRGBColorSpace]; break;
case DISPLAY_P3_COLORSPACE: cs = [NSColorSpace displayP3ColorSpace]; break;
case DEFAULT_COLORSPACE: cs = nil; break; // using deviceRGBColorSpace causes a hang when transitioning to fullscreen

5
glfw/wl_window.c vendored
View file

@ -1741,9 +1741,10 @@ void _glfwPlatformHideWindow(_GLFWwindow* window)
debug("Window %llu unmapped\n", window->id);
}
bool _glfwPlatformSetLayerShellConfig(_GLFWwindow* window, const GLFWLayerShellConfig *value) {
bool
_glfwPlatformSetLayerShellConfig(_GLFWwindow* window, const GLFWLayerShellConfig *value) {
if (!is_layer_shell(window)) return false;
window->wl.layer_shell.config = *value;
if (value) window->wl.layer_shell.config = *value;
layer_set_properties(window);
commit_window_surface(window);
return true;

View file

@ -129,6 +129,16 @@ min_size_for_os_window(OSWindow *window, int *min_width, int *min_height) {
static void get_window_dpi(GLFWwindow *w, double *x, double *y);
static void get_window_content_scale(GLFWwindow *w, float *xscale, float *yscale, double *xdpi, double *ydpi);
static bool
set_layer_shell_config_for(OSWindow *w, GLFWLayerShellConfig *lsc) {
if (lsc) {
lsc->related.background_opacity = w->background_opacity;
lsc->related.background_blur = OPT(background_blur);
lsc->related.color_space = OPT(macos_colorspace);
}
return glfwSetLayerShellConfig(w->handle, lsc);
}
void
update_os_window_viewport(OSWindow *window, bool notify_boss) {
int w, h, fw, fh;
@ -171,6 +181,7 @@ update_os_window_viewport(OSWindow *window, bool notify_boss) {
if (notify_boss) {
call_boss(on_window_resize, "KiiO", window->id, window->viewport_width, window->viewport_height, dpi_changed ? Py_True : Py_False);
}
if (dpi_changed && window->is_layer_shell && window->handle) set_layer_shell_config_for(window, NULL);
}
// callbacks {{{
@ -1197,14 +1208,18 @@ layer_shell_config_from_python(PyObject *p, GLFWLayerShellConfig *ans) {
#undef A
}
static bool
set_layer_shell_config_for(OSWindow *w, GLFWLayerShellConfig *lsc) {
lsc->related.background_opacity = w->background_opacity;
lsc->related.background_blur = OPT(background_blur);
lsc->related.color_space = OPT(macos_colorspace);
return glfwSetLayerShellConfig(w->handle, lsc);
static void
os_window_update_size_increments(OSWindow *window) {
if (OPT(resize_in_steps)) {
if (window->handle && window->fonts_data) glfwSetWindowSizeIncrements(
window->handle, window->fonts_data->fcm.cell_width, window->fonts_data->fcm.cell_height);
} else {
if (window->handle) glfwSetWindowSizeIncrements(
window->handle, GLFW_DONT_CARE, GLFW_DONT_CARE);
}
}
static PyObject*
create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) {
int x = INT_MIN, y = INT_MIN, window_state = WINDOW_NORMAL, disallow_override_title = 0;
@ -1440,14 +1455,12 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) {
}
void
os_window_update_size_increments(OSWindow *window) {
if (OPT(resize_in_steps)) {
if (window->handle && window->fonts_data) glfwSetWindowSizeIncrements(
window->handle, window->fonts_data->fcm.cell_width, window->fonts_data->fcm.cell_height);
} else {
if (window->handle) glfwSetWindowSizeIncrements(
window->handle, GLFW_DONT_CARE, GLFW_DONT_CARE);
}
on_os_window_font_size_change(OSWindow *os_window, double new_sz) {
double xdpi, ydpi; float xscale, yscale;
get_os_window_content_scale(os_window, &xdpi, &ydpi, &xscale, &yscale);
os_window->fonts_data = load_fonts_data(new_sz, xdpi, ydpi);
os_window_update_size_increments(os_window);
if (os_window->is_layer_shell) set_layer_shell_config_for(os_window, NULL);
}
#ifdef __APPLE__

View file

@ -1082,9 +1082,7 @@ PYWRAP1(os_window_font_size) {
PA("K|dp", &os_window_id, &new_sz, &force);
WITH_OS_WINDOW(os_window_id)
if (new_sz > 0 && (force || new_sz != os_window->fonts_data->font_sz_in_pts)) {
double xdpi, ydpi; float xscale, yscale;
get_os_window_content_scale(os_window, &xdpi, &ydpi, &xscale, &yscale);
os_window->fonts_data = load_fonts_data(new_sz, xdpi, ydpi);
on_os_window_font_size_change(os_window, new_sz);
send_prerendered_sprites_for_window(os_window);
resize_screen(os_window, os_window->tab_bar_render_data.screen, false);
for (size_t ti = 0; ti < os_window->num_tabs; ti++) {
@ -1094,7 +1092,6 @@ PYWRAP1(os_window_font_size) {
resize_screen(os_window, w->render_data.screen, true);
}
}
os_window_update_size_increments(os_window);
// On Wayland with CSD title needs to be re-rendered in a different font size
if (os_window->window_title && global_state.is_wayland) set_os_window_title(os_window, NULL);
}

View file

@ -419,7 +419,7 @@ void remove_main_loop_timer(id_type timer_id);
void update_main_loop_timer(id_type timer_id, monotonic_t interval, bool enabled);
void run_main_loop(tick_callback_fun, void*);
void stop_main_loop(void);
void os_window_update_size_increments(OSWindow *window);
void on_os_window_font_size_change(OSWindow *window, double new_sz);
void set_os_window_title_from_window(Window *w, OSWindow *os_window);
void update_os_window_title(OSWindow *os_window);
void fake_scroll(Window *w, int amount, bool upwards);