From 21d586cc86e8d700289175e4873c53cfb591c026 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 12 Sep 2018 10:44:24 +0530 Subject: [PATCH] macOS: Fix resizing semi-transparent windows causing the windows to be invisible during the resize Fixes #941 Workaround for https://github.com/glfw/glfw/issues/1251 --- docs/changelog.rst | 2 ++ kitty/glfw.c | 11 +++++++++++ kitty/shaders.c | 13 +++++++++---- kitty/state.h | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 478d8a319..bde7fb038 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -43,6 +43,8 @@ Changelog - Fix kitty @set-colors not working for tab backgrounds when using the `fade` tabbar style (:iss:`937`) +- macOS: Fix resizing semi-transparent windows causing the windows to be + invisible during the resize (:iss:`941`) 0.12.1 [2018-09-08] ------------------------------ diff --git a/kitty/glfw.c b/kitty/glfw.c index e24fef8b2..6a32b817c 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -106,6 +106,17 @@ framebuffer_size_callback(GLFWwindow *w, int width, int height) { window->has_pending_resizes = true; global_state.has_pending_resizes = true; window->last_resize_event_at = monotonic(); unjam_event_loop(); +#ifdef __APPLE__ + // Cocoa starts a sub-loop inside wait events which means main_loop + // stays stuck and no rendering happens. This causes the window to be + // blank. This is particularly bad for semi-transparent windows since + // they are rendered as invisible, so for that case we manually render. + if (global_state.callback_os_window->is_semi_transparent) { + make_os_window_context_current(global_state.callback_os_window); + blank_os_window(global_state.callback_os_window); + swap_window_buffers(global_state.callback_os_window); + } +#endif } else log_error("Ignoring resize request for tiny size: %dx%d", width, height); global_state.callback_os_window = NULL; } diff --git a/kitty/shaders.c b/kitty/shaders.c index 5c630aed3..1f3f1c1c3 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -426,15 +426,20 @@ set_cell_uniforms(float current_inactive_text_alpha) { } } +void +blank_os_window(OSWindow *os_window) { +#define C(shift) (((GLfloat)((OPT(background) >> shift) & 0xFF)) / 255.0f) + glClearColor(C(16), C(8), C(0), os_window->is_semi_transparent ? os_window->background_opacity : 1.0f); +#undef C + glClear(GL_COLOR_BUFFER_BIT); +} + bool send_cell_data_to_gpu(ssize_t vao_idx, ssize_t gvao_idx, GLfloat xstart, GLfloat ystart, GLfloat dx, GLfloat dy, Screen *screen, OSWindow *os_window) { bool changed = false; if (os_window->clear_count < 2) { os_window->clear_count++; -#define C(shift) (((GLfloat)((OPT(background) >> shift) & 0xFF)) / 255.0f) - glClearColor(C(16), C(8), C(0), os_window->is_semi_transparent ? os_window->background_opacity : 1.0f); -#undef C - glClear(GL_COLOR_BUFFER_BIT); + blank_os_window(os_window); changed = true; } if (os_window->fonts_data) { diff --git a/kitty/state.h b/kitty/state.h index 1e83315b6..7ca18771a 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -189,6 +189,7 @@ void update_surface_size(int, int, uint32_t); void free_texture(uint32_t*); void send_image_to_gpu(uint32_t*, const void*, int32_t, int32_t, bool, bool); void send_sprite_to_gpu(FONTS_DATA_HANDLE fg, unsigned int, unsigned int, unsigned int, pixel*); +void blank_os_window(OSWindow *); void set_titlebar_color(OSWindow *w, color_type color); FONTS_DATA_HANDLE load_fonts_data(double, double, double); void send_prerendered_sprites_for_window(OSWindow *w);