macOS: Allow hiding the titlebar only instead of all window decorations

Thanks to @ntruong for writing cb8279ec54 and  6807411365, the code was very helpful.
This commit is contained in:
Luflosi
2020-01-04 17:34:21 +01:00
parent bbf247c5c0
commit ea1ef709c6
5 changed files with 40 additions and 6 deletions

View File

@@ -500,6 +500,26 @@ cocoa_hide_window_title(void *w)
} // autoreleasepool } // 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[] = { static PyMethodDef module_methods[] = {
{"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""}, {"cocoa_get_lang", (PyCFunction)cocoa_get_lang, METH_NOARGS, ""},
{"cocoa_set_new_window_trigger", (PyCFunction)cocoa_set_new_window_trigger, METH_VARARGS, ""}, {"cocoa_set_new_window_trigger", (PyCFunction)cocoa_set_new_window_trigger, METH_VARARGS, ""},

View File

@@ -662,8 +662,18 @@ Fade the text in inactive windows by the specified amount (a number between
zero and one, with zero being fully faded). 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 Whether this works and exactly what effect it has depends on the
window manager/operating system. window manager/operating system.
''')) '''))

View File

@@ -14,6 +14,7 @@ extern bool cocoa_make_window_resizable(void *w, bool);
extern void cocoa_focus_window(void *w); extern void cocoa_focus_window(void *w);
extern void cocoa_create_global_menu(void); extern void cocoa_create_global_menu(void);
extern void cocoa_hide_window_title(void *w); 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_activation_policy(bool);
extern void cocoa_set_titlebar_color(void *w, color_type color); extern void cocoa_set_titlebar_color(void *w, color_type color);
extern bool cocoa_alt_option_key_pressed(unsigned long); 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 // We don't use depth and stencil buffers
glfwWindowHint(GLFW_DEPTH_BITS, 0); glfwWindowHint(GLFW_DEPTH_BITS, 0);
glfwWindowHint(GLFW_STENCIL_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__ #ifdef __APPLE__
cocoa_set_activation_policy(OPT(macos_hide_from_tasks)); cocoa_set_activation_policy(OPT(macos_hide_from_tasks));
glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, true); glfwWindowHint(GLFW_COCOA_GRAPHICS_SWITCHING, true);
@@ -652,7 +653,9 @@ create_os_window(PyObject UNUSED *self, PyObject *args) {
glfwSetDropCallback(glfw_window, drop_callback); glfwSetDropCallback(glfw_window, drop_callback);
#ifdef __APPLE__ #ifdef __APPLE__
if (glfwGetCocoaWindow) { 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_hide_window_title(glfwGetCocoaWindow(glfw_window));
} }
cocoa_make_window_resizable(glfwGetCocoaWindow(glfw_window), OPT(macos_window_resizable)); cocoa_make_window_resizable(glfwGetCocoaWindow(glfw_window), OPT(macos_window_resizable));

View File

@@ -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 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) #define S(name, convert) SS(name, OPT(name), convert)
SS(kitty_mod, kitty_mod, PyLong_AsLong); 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(visual_bell_duration, parse_s_double_to_monotonic_t);
S(enable_audio_bell, PyObject_IsTrue); S(enable_audio_bell, PyObject_IsTrue);
S(focus_follows_mouse, PyObject_IsTrue); S(focus_follows_mouse, PyObject_IsTrue);

View File

@@ -28,7 +28,8 @@ typedef struct {
color_type url_color, background, foreground, active_border_color, inactive_border_color, bell_border_color; 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; color_type mark1_foreground, mark1_background, mark2_foreground, mark2_background, mark3_foreground, mark3_background;
monotonic_t repaint_delay, input_delay; 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; bool macos_hide_from_tasks, macos_quit_when_last_window_closed, macos_window_resizable, macos_traditional_fullscreen;
unsigned int macos_option_as_alt; unsigned int macos_option_as_alt;
float macos_thicken_font; float macos_thicken_font;