mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-14 12:37:48 +02:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4d4ed718f | ||
|
|
836724709e | ||
|
|
96d2567815 | ||
|
|
419f43ceed | ||
|
|
47851ebb1b | ||
|
|
24a4fbd987 |
27
kitty/cocoa_window.m
Normal file
27
kitty/cocoa_window.m
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* cocoa_window.m
|
||||
* Copyright (C) 2017 Kovid Goyal <kovid at kovidgoyal.net>
|
||||
*
|
||||
* Distributed under terms of the GPL3 license.
|
||||
*/
|
||||
|
||||
|
||||
#include "data-types.h"
|
||||
#include <Cocoa/Cocoa.h>
|
||||
|
||||
#ifndef NSWindowStyleMaskTitled
|
||||
#define NSWindowStyleMaskTitled NSTitledWindowMask
|
||||
#endif
|
||||
|
||||
PyObject*
|
||||
cocoa_hide_titlebar(PyObject UNUSED *self, PyObject *window_id) {
|
||||
NSWindow *window = (NSWindow*)PyLong_AsVoidPtr(window_id);
|
||||
|
||||
@try {
|
||||
[window setStyleMask:
|
||||
[window styleMask] & ~NSWindowStyleMaskTitled];
|
||||
} @catch (NSException *e) {
|
||||
return PyErr_Format(PyExc_ValueError, "Failed to set style mask: %s: %s", [[e name] UTF8String], [[e reason] UTF8String]);
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
@@ -99,6 +99,7 @@ as_color(ColorProfile *self, PyObject *val) {
|
||||
break;
|
||||
case 2:
|
||||
col = entry >> 8;
|
||||
break;
|
||||
default:
|
||||
ans = Py_None; Py_INCREF(Py_None);
|
||||
}
|
||||
|
||||
@@ -173,6 +173,7 @@ type_map = {
|
||||
'initial_window_width': int,
|
||||
'initial_window_height': int,
|
||||
'use_system_wcwidth': to_bool,
|
||||
'macos_hide_titlebar': to_bool,
|
||||
}
|
||||
|
||||
for name in (
|
||||
|
||||
@@ -15,7 +15,7 @@ from .fast_data_types import (
|
||||
GLFW_KEY_LEFT_SUPER, GLFW_KEY_RIGHT_SUPER)
|
||||
|
||||
appname = 'kitty'
|
||||
version = (0, 2, 5)
|
||||
version = (0, 2, 6)
|
||||
str_version = '.'.join(map(str, version))
|
||||
_plat = sys.platform.lower()
|
||||
isosx = 'darwin' in _plat
|
||||
|
||||
15
kitty/glfw.c
15
kitty/glfw.c
@@ -7,6 +7,10 @@
|
||||
#include "data-types.h"
|
||||
#include <structmember.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#if defined(__APPLE__)
|
||||
#define GLFW_EXPOSE_NATIVE_COCOA
|
||||
#include <GLFW/glfw3native.h>
|
||||
#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 __APPLE__
|
||||
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 __APPLE__
|
||||
MND(cocoa_window_id, METH_NOARGS),
|
||||
#endif
|
||||
MND(set_should_close, METH_VARARGS),
|
||||
MND(set_input_mode, METH_VARARGS),
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -237,3 +237,9 @@ map ctrl+shift+backspace restore_font_size
|
||||
# For example:
|
||||
#
|
||||
# symbol_map U+E0A0-U+E0A2,U+E0B0-U+E0B3 PowerlineSymbols
|
||||
|
||||
|
||||
# OS specific tweaks
|
||||
|
||||
# Hide the kitty window's title bar on macOS.
|
||||
macos_hide_titlebar no
|
||||
|
||||
@@ -191,7 +191,11 @@ def run_app(opts, args):
|
||||
window = Window(viewport_size.width, viewport_size.height, args.cls)
|
||||
window.set_title(appname)
|
||||
window.make_context_current()
|
||||
if not isosx:
|
||||
if isosx:
|
||||
if opts.macos_hide_titlebar:
|
||||
from .fast_data_types import cocoa_hide_titlebar
|
||||
cocoa_hide_titlebar(window.cocoa_window_id())
|
||||
else:
|
||||
with open(logo_data_file, 'rb') as f:
|
||||
window.set_icon(f.read(), 256, 256)
|
||||
viewport_size.width, viewport_size.height = window.get_framebuffer_size()
|
||||
|
||||
@@ -543,6 +543,7 @@ accumulate_osc(Screen *screen, uint32_t ch, PyObject DUMP_UNUSED *dump_callback)
|
||||
screen->parser_buf_pos--;
|
||||
return true;
|
||||
}
|
||||
/* fallthrough */
|
||||
default:
|
||||
if (screen->parser_buf_pos >= PARSER_BUF_SZ - 1) {
|
||||
REPORT_ERROR("OSC sequence too long, truncating.");
|
||||
@@ -594,6 +595,7 @@ accumulate_oth(Screen *screen, uint32_t ch, PyObject DUMP_UNUSED *dump_callback)
|
||||
screen->parser_buf_pos--;
|
||||
return true;
|
||||
}
|
||||
/* fallthrough */
|
||||
default:
|
||||
if (screen->parser_buf_pos >= PARSER_BUF_SZ - 1) {
|
||||
REPORT_ERROR("OTH sequence too long, truncating.");
|
||||
|
||||
2
setup.py
2
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:
|
||||
|
||||
Reference in New Issue
Block a user