From ea1ef709c6bdeaea153f3362989d7db94d003156 Mon Sep 17 00:00:00 2001 From: Luflosi Date: Sat, 4 Jan 2020 17:34:21 +0100 Subject: [PATCH] macOS: Allow hiding the titlebar only instead of all window decorations Thanks to @ntruong for writing https://github.com/ntruong/kitty/commit/cb8279ec54cd81926e94ef0f94b4ebd05880258e and https://github.com/ntruong/kitty/commit/68074113652f283b5aef4cefd4bb35bded07dd13, the code was very helpful. --- kitty/cocoa_window.m | 20 ++++++++++++++++++++ kitty/config_data.py | 14 ++++++++++++-- kitty/glfw.c | 7 +++++-- kitty/state.c | 2 +- kitty/state.h | 3 ++- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index db88736132a..4366dfc470d 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -500,6 +500,26 @@ - (void)openFilesFromPasteboard:(NSPasteboard *)pasteboard type:(int)type { } // autoreleasepool } +void +cocoa_hide_titlebar(void *w) +{ + @autoreleasepool { + + cocoa_hide_window_title(w); + + NSWindow *window = (NSWindow*)w; + + [window standardWindowButton: NSWindowCloseButton].hidden = true; + [window standardWindowButton: NSWindowMiniaturizeButton].hidden = true; + [window standardWindowButton: NSWindowZoomButton].hidden = true; + + [window setTitlebarAppearsTransparent:YES]; + [window setStyleMask: + [window styleMask] | NSWindowStyleMaskFullSizeContentView]; + + } // autoreleasepool +} + static PyMethodDef module_methods[] = { {"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""}, {"cocoa_set_new_window_trigger", (PyCFunction)cocoa_set_new_window_trigger, METH_VARARGS, ""}, diff --git a/kitty/config_data.py b/kitty/config_data.py index 4886ae140ab..3a31df70ed7 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -662,8 +662,18 @@ def to_layout_names(raw): zero and one, with zero being fully faded). ''')) -o('hide_window_decorations', False, long_text=_(''' -Hide the window decorations (title-bar and window borders). + +def hide_window_decorations(x): + if x == 'titlebar-only': + return 0b10 + elif to_bool(x): + return 0b01 + return 0b00 + + +o('hide_window_decorations', 'no', option_type=hide_window_decorations, long_text=_(''' +Hide the window decorations (title-bar and window borders) with :code:`yes`. +On macOS, :code:`titlebar-only` can be used to only hide the titlebar. Whether this works and exactly what effect it has depends on the window manager/operating system. ''')) diff --git a/kitty/glfw.c b/kitty/glfw.c index 26f6373bd5a..79ac0460bb9 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -14,6 +14,7 @@ extern bool cocoa_make_window_resizable(void *w, bool); extern void cocoa_focus_window(void *w); extern void cocoa_create_global_menu(void); extern void cocoa_hide_window_title(void *w); +extern void cocoa_hide_titlebar(void *w); extern void cocoa_set_activation_policy(bool); extern void cocoa_set_titlebar_color(void *w, color_type color); extern bool cocoa_alt_option_key_pressed(unsigned long); @@ -513,7 +514,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { // We don't use depth and stencil buffers glfwWindowHint(GLFW_DEPTH_BITS, 0); glfwWindowHint(GLFW_STENCIL_BITS, 0); - if (OPT(hide_window_decorations)) glfwWindowHint(GLFW_DECORATED, false); + if (OPT(hide_window_decorations) & 1) glfwWindowHint(GLFW_DECORATED, false); #ifdef __APPLE__ cocoa_set_activation_policy(OPT(macos_hide_from_tasks)); glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, true); @@ -652,7 +653,9 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { glfwSetDropCallback(glfw_window, drop_callback); #ifdef __APPLE__ if (glfwGetCocoaWindow) { - if (!(OPT(macos_show_window_title_in) & WINDOW)) { + if (OPT(hide_window_decorations) & 2) { + cocoa_hide_titlebar(glfwGetCocoaWindow(glfw_window)); + } else if (!(OPT(macos_show_window_title_in) & WINDOW)) { cocoa_hide_window_title(glfwGetCocoaWindow(glfw_window)); } cocoa_make_window_resizable(glfwGetCocoaWindow(glfw_window), OPT(macos_window_resizable)); diff --git a/kitty/state.c b/kitty/state.c index aae5f7708c8..a73d9603bcf 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -476,7 +476,7 @@ PYWRAP1(set_options) { #define SS(name, dest, convert) { GA(name); dest = convert(ret); Py_DECREF(ret); if (PyErr_Occurred()) return NULL; } #define S(name, convert) SS(name, OPT(name), convert) SS(kitty_mod, kitty_mod, PyLong_AsLong); - S(hide_window_decorations, PyObject_IsTrue); + S(hide_window_decorations, PyLong_AsUnsignedLong); S(visual_bell_duration, parse_s_double_to_monotonic_t); S(enable_audio_bell, PyObject_IsTrue); S(focus_follows_mouse, PyObject_IsTrue); diff --git a/kitty/state.h b/kitty/state.h index 0ef2938d5ac..fad1745a50d 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -28,7 +28,8 @@ typedef struct { color_type url_color, background, foreground, active_border_color, inactive_border_color, bell_border_color; color_type mark1_foreground, mark1_background, mark2_foreground, mark2_background, mark3_foreground, mark3_background; monotonic_t repaint_delay, input_delay; - bool focus_follows_mouse, hide_window_decorations; + bool focus_follows_mouse; + unsigned int hide_window_decorations; bool macos_hide_from_tasks, macos_quit_when_last_window_closed, macos_window_resizable, macos_traditional_fullscreen; unsigned int macos_option_as_alt; float macos_thicken_font;