mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-23 16:58:09 +02:00
Move preservation of OpenGL context into glfw
Allows us to avoid creating an extra hidden window.
This commit is contained in:
@@ -107,12 +107,22 @@ bool _glfwInitNSGL(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We use a globally shared context across all OS Windows so that
|
||||||
|
// if all OS Windows are closed the context does not have to be recreated
|
||||||
|
// with all associated data lost. On Apple kitty can remain running with no
|
||||||
|
// OS Windows.
|
||||||
|
static NSOpenGLContext* globally_shared_context = nil;
|
||||||
|
|
||||||
// Terminate OpenGL support
|
// Terminate OpenGL support
|
||||||
//
|
//
|
||||||
void _glfwTerminateNSGL(void)
|
void _glfwTerminateNSGL(void) {
|
||||||
{
|
if (globally_shared_context != nil) {
|
||||||
|
[globally_shared_context release];
|
||||||
|
globally_shared_context = nil;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Create the OpenGL context
|
// Create the OpenGL context
|
||||||
//
|
//
|
||||||
bool _glfwCreateContextNSGL(_GLFWwindow* window,
|
bool _glfwCreateContextNSGL(_GLFWwindow* window,
|
||||||
@@ -272,7 +282,7 @@ bool _glfwCreateContextNSGL(_GLFWwindow* window,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSOpenGLContext* share = nil;
|
NSOpenGLContext* share = globally_shared_context;
|
||||||
|
|
||||||
if (ctxconfig->share)
|
if (ctxconfig->share)
|
||||||
share = ctxconfig->share->context.nsgl.object;
|
share = ctxconfig->share->context.nsgl.object;
|
||||||
@@ -286,6 +296,9 @@ bool _glfwCreateContextNSGL(_GLFWwindow* window,
|
|||||||
"NSGL: Failed to create OpenGL context");
|
"NSGL: Failed to create OpenGL context");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (globally_shared_context == nil) {
|
||||||
|
globally_shared_context = [window->context.nsgl.object retain];
|
||||||
|
}
|
||||||
|
|
||||||
if (fbconfig->transparent)
|
if (fbconfig->transparent)
|
||||||
{
|
{
|
||||||
|
|||||||
12
kitty/glfw.c
12
kitty/glfw.c
@@ -1092,7 +1092,6 @@ change_state_for_os_window(OSWindow *w, int state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
static GLFWwindow *apple_preserve_common_context = NULL;
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
filter_option(int key UNUSED, int mods, unsigned int native_key UNUSED, unsigned long flags) {
|
filter_option(int key UNUSED, int mods, unsigned int native_key UNUSED, unsigned long flags) {
|
||||||
@@ -1410,13 +1409,6 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) {
|
|||||||
// used, so start with window visible unless hidden window requested.
|
// used, so start with window visible unless hidden window requested.
|
||||||
GLFWwindow *common_context = global_state.num_os_windows ? global_state.os_windows[0].handle : NULL;
|
GLFWwindow *common_context = global_state.num_os_windows ? global_state.os_windows[0].handle : NULL;
|
||||||
GLFWwindow *temp_window = NULL;
|
GLFWwindow *temp_window = NULL;
|
||||||
#ifdef __APPLE__
|
|
||||||
if (!apple_preserve_common_context) {
|
|
||||||
glfwWindowHint(GLFW_VISIBLE, false);
|
|
||||||
apple_preserve_common_context = glfwCreateWindow(1, 1, "kitty", NULL, common_context, NULL);
|
|
||||||
}
|
|
||||||
if (!common_context) common_context = apple_preserve_common_context;
|
|
||||||
#endif
|
|
||||||
glfwWindowHint(GLFW_VISIBLE, window_state != WINDOW_HIDDEN && global_state.is_wayland);
|
glfwWindowHint(GLFW_VISIBLE, window_state != WINDOW_HIDDEN && global_state.is_wayland);
|
||||||
float xscale, yscale;
|
float xscale, yscale;
|
||||||
double xdpi, ydpi;
|
double xdpi, ydpi;
|
||||||
@@ -2461,10 +2453,6 @@ run_main_loop(tick_callback_fun cb, void* cb_data) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
stop_main_loop(void) {
|
stop_main_loop(void) {
|
||||||
#ifdef __APPLE__
|
|
||||||
if (apple_preserve_common_context) glfwDestroyWindow(apple_preserve_common_context);
|
|
||||||
apple_preserve_common_context = NULL;
|
|
||||||
#endif
|
|
||||||
glfwStopMainLoop();
|
glfwStopMainLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user