From 772d6597a9c14e582e7335e8c1b3abf1f6911ffc Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 12 Sep 2018 21:27:49 +0530 Subject: [PATCH] macOS: Add an option :opt:`macos_traditional_fullscreen` to make full-screening of kitty windows much faster, but less pretty. See #911 --- docs/changelog.rst | 6 ++---- kitty/cocoa_window.m | 25 +++++++++++++++---------- kitty/config_data.py | 4 ++++ kitty/glfw.c | 26 +++++++++++++++----------- kitty/state.c | 1 + kitty/state.h | 2 +- 6 files changed, 38 insertions(+), 26 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 59bee1d7c..f57aa96e4 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -25,10 +25,8 @@ Changelog on macs thicker, which makes it similar to the result of sub-pixel antialiasing (:pull:`950`) -- macOS: Make full screening of kitty much faster by using the "traditional full - screen" mode of cocoa, similar to iTerm and MacVim (:iss:`911`). Also should - hopefully workaround a bug in glfw that causes crashes when unplugging - monitors with full screen windows. (:iss:`898`) +- macOS: Add an option :opt:`macos_traditional_fullscreen` to make + full-screening of kitty windows much faster, but less pretty. (:iss:`911`) - Fix a bug causing incorrect line ordering when viewing the scrollback buffer if the scrollback buffer is full (:iss:`960`) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index 0f26ec0a0..fbeb22c46 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -225,20 +225,25 @@ cocoa_focus_window(void *w) { } bool -cocoa_toggle_fullscreen(void *w) { +cocoa_toggle_fullscreen(void *w, bool traditional) { NSWindow *window = (NSWindow*)w; + bool made_fullscreen = true; NSWindowStyleMask sm = [window styleMask]; - bool made_fullscreen; - if (!(sm & NSWindowStyleMaskFullScreen)) { - made_fullscreen = true; - sm |= NSWindowStyleMaskBorderless | NSWindowStyleMaskFullScreen; - [[NSApplication sharedApplication] setPresentationOptions: NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock]; + bool in_fullscreen = sm & NSWindowStyleMaskFullScreen; + if (traditional) { + if (!(in_fullscreen)) { + sm |= NSWindowStyleMaskBorderless | NSWindowStyleMaskFullScreen; + [[NSApplication sharedApplication] setPresentationOptions: NSApplicationPresentationAutoHideMenuBar | NSApplicationPresentationAutoHideDock]; + } else { + made_fullscreen = false; + sm &= ~(NSWindowStyleMaskBorderless | NSWindowStyleMaskFullScreen); + [[NSApplication sharedApplication] setPresentationOptions: NSApplicationPresentationDefault]; + } + [window setStyleMask: sm]; } else { - made_fullscreen = false; - sm &= ~(NSWindowStyleMaskBorderless | NSWindowStyleMaskFullScreen); - [[NSApplication sharedApplication] setPresentationOptions: NSApplicationPresentationDefault]; + if (in_fullscreen) made_fullscreen = false; + [window toggleFullScreen: nil]; } - [window setStyleMask: sm]; return made_fullscreen; } diff --git a/kitty/config_data.py b/kitty/config_data.py index 0df1d3a4b..098d537b9 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -786,6 +786,10 @@ legibility at small font sizes. For example, a value of 0.75 will result in rendering that looks similar to sub-pixel antialiasing at common font sizes. ''')) + +o('macos_traditional_fullscreen', False, long_text=_(''' +Use the traditional full-screen transition, that is faster, but less pretty. +''')) # }}} g('shortcuts') # {{{ diff --git a/kitty/glfw.c b/kitty/glfw.c index cec4cea05..e8325cb42 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -10,7 +10,7 @@ #include "glfw-wrapper.h" extern bool cocoa_make_window_resizable(void *w, bool); extern void cocoa_focus_window(void *w); -extern bool cocoa_toggle_fullscreen(void *w); +extern bool cocoa_toggle_fullscreen(void *w, bool); extern void cocoa_create_global_menu(void); extern void cocoa_set_hide_from_tasks(void); extern void cocoa_set_titlebar_color(void *w, color_type color); @@ -362,16 +362,20 @@ toggle_fullscreen_for_os_window(OSWindow *w) { glfwGetWindowSize(w->handle, &width, &height); glfwGetWindowPos(w->handle, &x, &y); #ifdef __APPLE__ - if (cocoa_toggle_fullscreen(glfwGetCocoaWindow(w->handle))) { - w->before_fullscreen.is_set = true; - w->before_fullscreen.w = width; w->before_fullscreen.h = height; w->before_fullscreen.x = x; w->before_fullscreen.y = y; - return true; + if (OPT(macos_traditional_fullscreen)) { + if (cocoa_toggle_fullscreen(glfwGetCocoaWindow(w->handle), true)) { + w->before_fullscreen.is_set = true; + w->before_fullscreen.w = width; w->before_fullscreen.h = height; w->before_fullscreen.x = x; w->before_fullscreen.y = y; + return true; + } + if (w->before_fullscreen.is_set) { + glfwSetWindowSize(w->handle, w->before_fullscreen.w, w->before_fullscreen.h); + glfwSetWindowPos(w->handle, w->before_fullscreen.x, w->before_fullscreen.y); + } + return false; + } else { + return cocoa_toggle_fullscreen(glfwGetCocoaWindow(w->handle), false); } - if (w->before_fullscreen.is_set) { - glfwSetWindowSize(w->handle, w->before_fullscreen.w, w->before_fullscreen.h); - glfwSetWindowPos(w->handle, w->before_fullscreen.x, w->before_fullscreen.y); - } - return false; #else GLFWmonitor *monitor; if ((monitor = glfwGetWindowMonitor(w->handle)) == NULL) { @@ -418,7 +422,7 @@ on_application_reopen(int has_visible_windows) { static int intercept_cocoa_fullscreen(GLFWwindow *w) { - if (!set_callback_window(w)) return 0; + if (!OPT(macos_traditional_fullscreen) || !set_callback_window(w)) return 0; toggle_fullscreen_for_os_window(global_state.callback_os_window); global_state.callback_os_window = NULL; return 1; diff --git a/kitty/state.c b/kitty/state.c index 4874e33ba..089e70053 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -386,6 +386,7 @@ PYWRAP1(set_options) { S(close_on_child_death, PyObject_IsTrue); S(window_alert_on_bell, PyObject_IsTrue); S(macos_option_as_alt, PyObject_IsTrue); + S(macos_traditional_fullscreen, PyObject_IsTrue); S(macos_hide_titlebar, PyObject_IsTrue); S(macos_quit_when_last_window_closed, PyObject_IsTrue); S(macos_window_resizable, PyObject_IsTrue); diff --git a/kitty/state.h b/kitty/state.h index 7ca18771a..94a6f7038 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -23,7 +23,7 @@ typedef struct { color_type url_color, background, active_border_color, inactive_border_color, bell_border_color; double repaint_delay, input_delay; bool focus_follows_mouse; - bool macos_option_as_alt, macos_hide_titlebar, macos_hide_from_tasks, x11_hide_window_decorations, macos_quit_when_last_window_closed, macos_window_resizable; + bool macos_option_as_alt, macos_hide_titlebar, macos_hide_from_tasks, x11_hide_window_decorations, macos_quit_when_last_window_closed, macos_window_resizable, macos_traditional_fullscreen; float macos_thicken_font; int adjust_line_height_px, adjust_column_width_px; float adjust_line_height_frac, adjust_column_width_frac;