From abd4de731102ef13651b760bb0aef05cc2ced573 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 20 Feb 2019 20:09:15 +0530 Subject: [PATCH] macOS: Fix :opt:`sync_to_monitor` not working on Mojave. --- docs/changelog.rst | 2 ++ kitty/child-monitor.c | 7 ++++--- kitty/glfw.c | 36 ++++++++++++++++++++++++++---------- kitty/state.c | 4 ++++ kitty/state.h | 7 ++++--- 5 files changed, 40 insertions(+), 16 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 1f2535afb..7d913666c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -64,6 +64,8 @@ To update |kitty|, :doc:`follow the instructions `. - macOS: When closing a top-level window only switch focus to the previous kitty window if it is on the same workspace (:iss:`1379`) +- macOS: Fix :opt:`sync_to_monitor` not working on Mojave. + 0.13.3 [2019-01-19] ------------------------------ diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 97628cbdf..2b7a45b92 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -26,6 +26,7 @@ extern PyTypeObject Screen_Type; // Apple does not implement MSG_NOSIGNAL #define MSG_NOSIGNAL 0 #endif +#define USE_RENDER_FRAMES (global_state.has_render_frames && OPT(sync_to_monitor)) static void (*parse_func)(Screen*, PyObject*, double); @@ -638,7 +639,7 @@ render_os_window(OSWindow *os_window, double now, unsigned int active_window_id, os_window->last_active_tab = os_window->active_tab; os_window->last_num_tabs = os_window->num_tabs; os_window->last_active_window_id = active_window_id; os_window->focused_at_last_render = os_window->is_focused; os_window->is_damaged = false; - if (global_state.is_wayland && OPT(sync_to_monitor)) wayland_request_frame_render(os_window); + if (USE_RENDER_FRAMES) request_frame_render(os_window); #undef WD #undef TD } @@ -667,8 +668,8 @@ render(double now) { update_os_window_title(w); continue; } - if (global_state.is_wayland && w->wayland_render_state != RENDER_FRAME_READY && OPT(sync_to_monitor)) { - if (w->wayland_render_state == RENDER_FRAME_NOT_REQUESTED) wayland_request_frame_render(w); + if (USE_RENDER_FRAMES && w->render_state != RENDER_FRAME_READY) { + if (w->render_state == RENDER_FRAME_NOT_REQUESTED) request_frame_render(w); continue; } bool needs_render = w->is_damaged; diff --git a/kitty/glfw.c b/kitty/glfw.c index 651f25ec3..a5d61dea3 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -555,10 +555,11 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { w->fonts_data = fonts_data; w->shown_once = true; w->last_focused_counter = ++focus_counter; - glfwSwapInterval(OPT(sync_to_monitor) && !global_state.is_wayland ? 1 : 0); #ifdef __APPLE__ if (OPT(macos_option_as_alt)) glfwSetCocoaTextInputFilter(glfw_window, filter_option); glfwSetCocoaToggleFullscreenIntercept(glfw_window, intercept_cocoa_fullscreen); +#else + glfwSwapInterval(OPT(sync_to_monitor) && !global_state.is_wayland ? 1 : 0); #endif send_prerendered_sprites_for_window(w); if (logo.pixels && logo.width && logo.height) glfwSetWindowIcon(glfw_window, 1, &logo); @@ -1037,25 +1038,40 @@ void get_cocoa_key_equivalent(int key, int mods, unsigned short *cocoa_key, int *cocoa_mods) { glfwGetCocoaKeyEquivalent(key, mods, cocoa_key, cocoa_mods); } -#endif -void -wayland_frame_request_callback(id_type os_window_id) { +static void +cocoa_frame_request_callback(GLFWwindow *window) { for (size_t i = 0; i < global_state.num_os_windows; i++) { - if (global_state.os_windows[i].id == os_window_id) { - global_state.os_windows[i].wayland_render_state = RENDER_FRAME_READY; + if (global_state.os_windows[i].handle == window) { + global_state.os_windows[i].render_state = RENDER_FRAME_READY; break; } } } void -wayland_request_frame_render(OSWindow *w) { - glfwRequestWaylandFrameEvent(w->handle, w->id, wayland_frame_request_callback); - w->wayland_render_state = RENDER_FRAME_REQUESTED; +request_frame_render(OSWindow *w) { + glfwCocoaRequestRenderFrame(w->handle, cocoa_frame_request_callback); + w->render_state = RENDER_FRAME_REQUESTED; } -#ifndef __APPLE__ +#else + +static void +wayland_frame_request_callback(id_type os_window_id) { + for (size_t i = 0; i < global_state.num_os_windows; i++) { + if (global_state.os_windows[i].id == os_window_id) { + global_state.os_windows[i].render_state = RENDER_FRAME_READY; + break; + } + } +} + +void +request_frame_render(OSWindow *w) { + glfwRequestWaylandFrameEvent(w->handle, w->id, wayland_frame_request_callback); + w->render_state = RENDER_FRAME_REQUESTED; +} void dbus_notification_created_callback(unsigned long long notification_id, uint32_t new_notification_id, void* data UNUSED) { diff --git a/kitty/state.c b/kitty/state.c index 7d4ca137a..68a5a821e 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -351,6 +351,10 @@ PYWRAP1(set_options) { int is_wayland = 0, debug_gl = 0, debug_font_fallback = 0; PA("O|ppp", &opts, &is_wayland, &debug_gl, &debug_font_fallback); global_state.is_wayland = is_wayland ? true : false; +#ifdef __APPLE__ + global_state.has_render_frames = true; +#endif + if (global_state.is_wayland) global_state.has_render_frames = true; global_state.debug_gl = debug_gl ? true : false; global_state.debug_font_fallback = debug_font_fallback ? true : false; #define GA(name) ret = PyObject_GetAttrString(opts, #name); if (ret == NULL) return NULL; diff --git a/kitty/state.h b/kitty/state.h index 79cb8863d..ba4c3ffe2 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -104,7 +104,7 @@ typedef struct { bool is_set; } OSWindowGeometry; -enum WAYLAND_RENDER_STATE { RENDER_FRAME_NOT_REQUESTED, RENDER_FRAME_REQUESTED, RENDER_FRAME_READY }; +enum RENDER_STATE { RENDER_FRAME_NOT_REQUESTED, RENDER_FRAME_REQUESTED, RENDER_FRAME_READY }; typedef struct { void *handle; @@ -134,7 +134,7 @@ typedef struct { FONTS_DATA_HANDLE fonts_data; id_type temp_font_group_id; double pending_scroll_pixels; - enum WAYLAND_RENDER_STATE wayland_render_state; + enum RENDER_STATE render_state; id_type last_focused_counter; } OSWindow; @@ -149,6 +149,7 @@ typedef struct { OSWindow *callback_os_window; bool terminate; bool is_wayland; + bool has_render_frames; bool debug_gl, debug_font_fallback; bool has_pending_resizes; bool in_sequence_mode; @@ -219,4 +220,4 @@ void set_cocoa_pending_action_with_wd(CocoaPendingAction action, const char *wd) bool application_quit_requested(); void request_application_quit(); #endif -void wayland_request_frame_render(OSWindow *w); +void request_frame_render(OSWindow *w);