From c76db4bfb44ab9544dab49097a28e07ed06a93dd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 25 Dec 2023 17:20:52 +0530 Subject: [PATCH] Wayland: Redraw titlebar title on font size change Fixes #6945 --- glfw/glfw.py | 1 + glfw/wl_window.c | 5 +++++ kitty/glfw-wrapper.c | 3 +++ kitty/glfw-wrapper.h | 4 ++++ kitty/glfw.c | 4 ++++ kitty/state.c | 3 +++ 6 files changed, 20 insertions(+) diff --git a/glfw/glfw.py b/glfw/glfw.py index 393e66a9e..f308657b9 100755 --- a/glfw/glfw.py +++ b/glfw/glfw.py @@ -262,6 +262,7 @@ def generate_wrappers(glfw_header: str) -> None: void glfwWaylandActivateWindow(GLFWwindow *handle, const char *activation_token) void glfwWaylandRunWithActivationToken(GLFWwindow *handle, GLFWactivationcallback cb, void *cb_data) bool glfwWaylandSetTitlebarColor(GLFWwindow *handle, uint32_t color, bool use_system_color) + void glfwWaylandRedrawCSDWindowTitle(GLFWwindow *handle) unsigned long long glfwDBusUserNotify(const char *app_name, const char* icon, const char *summary, const char *body, \ const char *action_text, int32_t timeout, GLFWDBusnotificationcreatedfun callback, void *data) void glfwDBusSetUserNotificationHandler(GLFWDBusnotificationactivatedfun handler) diff --git a/glfw/wl_window.c b/glfw/wl_window.c index 3775a4ef0..331e9cc12 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -2332,3 +2332,8 @@ GLFWAPI bool glfwWaylandSetTitlebarColor(GLFWwindow *handle, uint32_t color, boo } return false; } + +GLFWAPI void glfwWaylandRedrawCSDWindowTitle(GLFWwindow *handle) { + _GLFWwindow* window = (_GLFWwindow*) handle; + change_csd_title(window); +} diff --git a/kitty/glfw-wrapper.c b/kitty/glfw-wrapper.c index f9a70d7db..f14c24cdc 100644 --- a/kitty/glfw-wrapper.c +++ b/kitty/glfw-wrapper.c @@ -479,6 +479,9 @@ load_glfw(const char* path) { *(void **) (&glfwWaylandSetTitlebarColor_impl) = dlsym(handle, "glfwWaylandSetTitlebarColor"); if (glfwWaylandSetTitlebarColor_impl == NULL) dlerror(); // clear error indicator + *(void **) (&glfwWaylandRedrawCSDWindowTitle_impl) = dlsym(handle, "glfwWaylandRedrawCSDWindowTitle"); + if (glfwWaylandRedrawCSDWindowTitle_impl == NULL) dlerror(); // clear error indicator + *(void **) (&glfwDBusUserNotify_impl) = dlsym(handle, "glfwDBusUserNotify"); if (glfwDBusUserNotify_impl == NULL) dlerror(); // clear error indicator diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index 88b3a2e71..4cd275e90 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -2291,6 +2291,10 @@ typedef bool (*glfwWaylandSetTitlebarColor_func)(GLFWwindow*, uint32_t, bool); GFW_EXTERN glfwWaylandSetTitlebarColor_func glfwWaylandSetTitlebarColor_impl; #define glfwWaylandSetTitlebarColor glfwWaylandSetTitlebarColor_impl +typedef void (*glfwWaylandRedrawCSDWindowTitle_func)(GLFWwindow*); +GFW_EXTERN glfwWaylandRedrawCSDWindowTitle_func glfwWaylandRedrawCSDWindowTitle_impl; +#define glfwWaylandRedrawCSDWindowTitle glfwWaylandRedrawCSDWindowTitle_impl + typedef unsigned long long (*glfwDBusUserNotify_func)(const char*, const char*, const char*, const char*, const char*, int32_t, GLFWDBusnotificationcreatedfun, void*); GFW_EXTERN glfwDBusUserNotify_func glfwDBusUserNotify_impl; #define glfwDBusUserNotify glfwDBusUserNotify_impl diff --git a/kitty/glfw.c b/kitty/glfw.c index e38bdcbc4..3e55723b0 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1686,6 +1686,10 @@ request_window_attention(id_type kitty_window_id, bool audio_bell) { void set_os_window_title(OSWindow *w, const char *title) { + if (!title) { + if (global_state.is_wayland) glfwWaylandRedrawCSDWindowTitle(w->handle); + return; + } static char buf[2048]; strip_csi_(title, buf, arraysz(buf)); glfwSetWindowTitle(w->handle, buf); diff --git a/kitty/state.c b/kitty/state.c index bb1b47023..f10735665 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -1035,6 +1035,9 @@ PYWRAP1(os_window_font_size) { } } 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); + } return Py_BuildValue("d", os_window->font_sz_in_pts); END_WITH_OS_WINDOW