From c5649df971236b4fd23504cf4b4909bf3796329a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 15 Nov 2017 14:18:01 +0530 Subject: [PATCH] Fix various bugs introduced by the refactoring to support OSWindow --- kitty/child-monitor.c | 5 ++++- kitty/gl.h | 2 +- kitty/glfw.c | 36 +++++++++++++++--------------------- kitty/main.py | 2 +- kitty/state.c | 8 ++++---- kitty/state.h | 2 +- 6 files changed, 26 insertions(+), 29 deletions(-) diff --git a/kitty/child-monitor.c b/kitty/child-monitor.c index 0bcf6ca43..5543caac0 100644 --- a/kitty/child-monitor.c +++ b/kitty/child-monitor.c @@ -554,7 +554,10 @@ render(double now) { for (size_t i = 0; i < global_state.num_os_windows; i++) { OSWindow *w = global_state.os_windows + i; if (!should_os_window_be_rendered(w)) continue; - make_window_context_current(w); + if (w->viewport_size_dirty) { + update_surface_size(w->viewport_width, w->viewport_height); + w->viewport_size_dirty = false; + } unsigned int active_window_id = 0; bool window_rendered = render_os_window(w, now, &active_window_id); bool tab_bar_changed = w->num_tabs > 1 && (w->last_active_tab != w->active_tab || w->last_num_tabs != w->num_tabs); diff --git a/kitty/gl.h b/kitty/gl.h index 0fe7f96e3..43d6202b7 100644 --- a/kitty/gl.h +++ b/kitty/gl.h @@ -60,7 +60,7 @@ gl_init() { } void -update_viewport_size(int w, int h) { +update_surface_size(int w, int h) { glViewport(0, 0, w, h); } diff --git a/kitty/glfw.c b/kitty/glfw.c index d13cd9b72..9ff9fdeec 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -167,30 +167,30 @@ set_default_window_icon(PyObject UNUSED *self, PyObject *args) { } static PyObject* -create_new_os_window(PyObject UNUSED *self, PyObject *args) { +create_os_window(PyObject UNUSED *self, PyObject *args) { int width, height; char *title; if (!PyArg_ParseTuple(args, "iis", &width, &height, &title)) return NULL; + bool is_first_window = standard_cursor == NULL; - if (standard_cursor == NULL) { - // The first window to be created + if (is_first_window) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_REQUIRED_VERSION_MAJOR); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_REQUIRED_VERSION_MINOR); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true); glfwWindowHint(GLFW_SAMPLES, 0); - glfwSwapInterval(0); // a value of 1 makes mouse selection laggy #ifdef __APPLE__ if (OPT(macos_hide_titlebar)) glfwWindowHint(GLFW_DECORATED, false); // OS X cannot handle 16bit stencil buffers glfwWindowHint(GLFW_STENCIL_BITS, 8); -#else #endif + standard_cursor = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); click_cursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR); arrow_cursor = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); if (standard_cursor == NULL || click_cursor == NULL || arrow_cursor == NULL) { - PyErr_SetString(PyExc_ValueError, "Failed to create standard mouse cursors"); return NULL; } + PyErr_SetString(PyExc_ValueError, "Failed to create standard mouse cursors"); return NULL; + } } if (global_state.num_os_windows >= MAX_CHILDREN) { @@ -203,13 +203,18 @@ create_new_os_window(PyObject UNUSED *self, PyObject *args) { glfw_window = glfwCreateWindow(640, 400, title, NULL, global_state.num_os_windows ? global_state.os_windows[0].handle : NULL); } if (glfw_window == NULL) { PyErr_SetString(PyExc_ValueError, "Failed to create GLFWwindow"); return NULL; } - if (logo.pixels && logo.width && logo.height) glfwSetWindowIcon(glfw_window, 1, &logo); + if (is_first_window) { + glfwMakeContextCurrent(glfw_window); + gl_init(); + glfwSwapInterval(0); // a value of 1 makes mouse selection laggy + } + OSWindow *w = add_os_window(); w->id = ++global_state.os_window_id_counter; - glfwSetWindowUserPointer(glfw_window, w); w->handle = glfw_window; + if (logo.pixels && logo.width && logo.height) glfwSetWindowIcon(glfw_window, 1, &logo); + glfwSetWindowUserPointer(glfw_window, w); glfwSetCursor(glfw_window, standard_cursor); - w->viewport_size_dirty = true; update_viewport(w); glfwSetFramebufferSizeCallback(glfw_window, framebuffer_size_callback); glfwSetCharModsCallback(glfw_window, char_mods_callback); @@ -419,17 +424,6 @@ hide_mouse(OSWindow *w) { glfwSetInputMode(w->handle, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); } -static OSWindow *current_ctx_window = NULL; - -void -make_window_context_current(OSWindow *w) { - if (current_ctx_window != w) { - glfwMakeContextCurrent(w->handle); - current_ctx_window = w; - if (w->viewport_size_dirty) update_viewport_size(w->viewport_width, w->viewport_height); - } -} - void swap_window_buffers(OSWindow *w) { glfwSwapBuffers(w->handle); @@ -486,7 +480,7 @@ primary_monitor_content_scale(PyObject UNUSED *self) { // Boilerplate {{{ static PyMethodDef module_methods[] = { - METHODB(create_new_os_window, METH_VARARGS), + METHODB(create_os_window, METH_VARARGS), METHODB(set_default_window_icon, METH_VARARGS), METHODB(get_clipboard_string, METH_NOARGS), METHODB(get_content_scale_for_window, METH_NOARGS), diff --git a/kitty/main.py b/kitty/main.py index 6f6aa324d..17d356809 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -142,7 +142,7 @@ def run_app(opts, args): set_scale(opts.box_drawing_scale) set_options(opts, iswayland, args.debug_gl) load_cached_values() - w, h = initial_window_size() + w, h = initial_window_size(opts) window_id = create_os_window(w, h, args.cls) startup_ctx = init_startup_notification(window_id) if isosx: diff --git a/kitty/state.c b/kitty/state.c index 1f5ff66ca..150e43049 100644 --- a/kitty/state.c +++ b/kitty/state.c @@ -425,22 +425,22 @@ KK5I(add_borders_rect) static PyMethodDef module_methods[] = { MW(current_os_window, METH_NOARGS), - MW(set_options, METH_O), + MW(set_options, METH_VARARGS), MW(handle_for_window_id, METH_VARARGS), MW(set_logical_dpi, METH_VARARGS), MW(add_tab, METH_O), MW(add_window, METH_VARARGS), MW(update_window_title, METH_VARARGS), - MW(remove_tab, METH_O), + MW(remove_tab, METH_VARARGS), MW(remove_window, METH_VARARGS), - MW(set_active_tab, METH_O), + MW(set_active_tab, METH_VARARGS), MW(set_active_window, METH_VARARGS), MW(swap_tabs, METH_VARARGS), MW(swap_windows, METH_VARARGS), MW(add_borders_rect, METH_VARARGS), MW(set_tab_bar_render_data, METH_VARARGS), MW(set_window_render_data, METH_VARARGS), - MW(viewport_for_window, METH_O), + MW(viewport_for_window, METH_VARARGS), MW(mark_os_window_for_close, METH_VARARGS), MW(update_window_visibility, METH_VARARGS), MW(set_boss, METH_O), diff --git a/kitty/state.h b/kitty/state.h index 091f3f8a7..ef3f20149 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -148,7 +148,7 @@ ssize_t create_graphics_vao(); ssize_t create_border_vao(); bool draw_cells(ssize_t, ssize_t, float, float, float, float, Screen *, OSWindow *); void draw_cursor(CursorRenderInfo *, bool); -void update_viewport_size(int, int); +void update_surface_size(int, int); void free_texture(uint32_t*); void send_image_to_gpu(uint32_t*, const void*, int32_t, int32_t, bool, bool); void send_sprite_to_gpu(unsigned int, unsigned int, unsigned int, uint8_t*);