diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m new file mode 100644 index 000000000..ddbf42ed4 --- /dev/null +++ b/kitty/cocoa_window.m @@ -0,0 +1,19 @@ +/* + * cocoa_window.m + * Copyright (C) 2017 Kovid Goyal + * + * Distributed under terms of the GPL3 license. + */ + + +#include "data-types.h" +#include + +PyObject* +cocoa_hide_titlebar(PyObject UNUSED *self, PyObject *window_id) { + NSView *native_view = (NSView*)PyLong_AsVoidPtr(window_id); + NSWindow* window = [native_view window]; + [window setStyleMask: + [window styleMask] & ~NSTitledWindowMask]; + Py_RETURN_NONE; +} diff --git a/kitty/glfw.c b/kitty/glfw.c index 36d1e92ad..311e155b1 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -7,6 +7,10 @@ #include "data-types.h" #include #include +#if defined(__APPLE__) +#define GLFW_EXPOSE_NATIVE_COCOA +#include +#endif #if GLFW_VERSION_MAJOR < 3 || (GLFW_VERSION_MAJOR == 3 && GLFW_VERSION_MINOR < 2) #error "glfw >= 3.2 required" @@ -373,6 +377,14 @@ request_window_attention(Window *self) { } #endif +#ifdef glfwGetCocoaWindow +static PyObject* +cocoa_window_id(Window *self) { + void *wid = glfwGetCocoaWindow(self->window); + if (wid == NULL) { PyErr_SetString(PyExc_ValueError, "Failed to get native window handle"); return NULL; } + return PyLong_FromVoidPtr(wid); +} +#endif // Boilerplate {{{ #define MND(name, args) {#name, (PyCFunction)name, args, ""} @@ -387,6 +399,9 @@ static PyMethodDef methods[] = { MND(current_monitor_dpi, METH_NOARGS), #ifdef glfwRequestWindowAttention MND(request_window_attention, METH_NOARGS), +#endif +#ifdef cocoa_window_id + MND(cocoa_window_id, METH_NOARGS), #endif MND(set_should_close, METH_VARARGS), MND(set_input_mode, METH_VARARGS), diff --git a/kitty/glfw.h b/kitty/glfw.h index 92c401cf2..860f2bb03 100644 --- a/kitty/glfw.h +++ b/kitty/glfw.h @@ -18,6 +18,13 @@ PyObject* glfw_post_empty_event(PyObject UNUSED *self); PyObject* glfw_get_physical_dpi(PyObject UNUSED *self); PyObject* glfw_get_key_name(PyObject UNUSED *self, PyObject *args); +#ifdef __APPLE__ +PyObject* cocoa_hide_titlebar(PyObject UNUSED *self, PyObject *window_id); +#define COCOA_HIDE_TITLEBAR {"cocoa_hide_titlebar", (PyCFunction)cocoa_hide_titlebar, METH_O, ""}, +#else +#define COCOA_HIDE_TITLEBAR +#endif + #define GLFW_FUNC_WRAPPERS \ {"glfw_set_error_callback", (PyCFunction)glfw_set_error_callback, METH_O, ""}, \ {"glfw_init", (PyCFunction)glfw_init, METH_NOARGS, ""}, \ @@ -28,4 +35,5 @@ PyObject* glfw_get_key_name(PyObject UNUSED *self, PyObject *args); {"glfw_post_empty_event", (PyCFunction)glfw_post_empty_event, METH_NOARGS, ""}, \ {"glfw_get_physical_dpi", (PyCFunction)glfw_get_physical_dpi, METH_NOARGS, ""}, \ {"glfw_get_key_name", (PyCFunction)glfw_get_key_name, METH_VARARGS, ""}, \ + COCOA_HIDE_TITLEBAR diff --git a/setup.py b/setup.py index e05a5054b..3127a0f11 100755 --- a/setup.py +++ b/setup.py @@ -266,7 +266,7 @@ def option_parser(): def find_c_files(): ans, headers = [], [] d = os.path.join(base, 'kitty') - exclude = {'freetype.c', 'fontconfig.c'} if isosx else {'core_text.m'} + exclude = {'freetype.c', 'fontconfig.c'} if isosx else {'core_text.m', 'cocoa_window.m'} for x in os.listdir(d): ext = os.path.splitext(x)[1] if ext in ('.c', '.m') and os.path.basename(x) not in exclude: