Fix various bugs introduced by the refactoring to support OSWindow

This commit is contained in:
Kovid Goyal 2017-11-15 14:18:01 +05:30
parent 9cedefb50c
commit c5649df971
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
6 changed files with 26 additions and 29 deletions

View File

@ -554,7 +554,10 @@ render(double now) {
for (size_t i = 0; i < global_state.num_os_windows; i++) { for (size_t i = 0; i < global_state.num_os_windows; i++) {
OSWindow *w = global_state.os_windows + i; OSWindow *w = global_state.os_windows + i;
if (!should_os_window_be_rendered(w)) continue; 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; unsigned int active_window_id = 0;
bool window_rendered = render_os_window(w, now, &active_window_id); 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); bool tab_bar_changed = w->num_tabs > 1 && (w->last_active_tab != w->active_tab || w->last_num_tabs != w->num_tabs);

View File

@ -60,7 +60,7 @@ gl_init() {
} }
void void
update_viewport_size(int w, int h) { update_surface_size(int w, int h) {
glViewport(0, 0, w, h); glViewport(0, 0, w, h);
} }

View File

@ -167,30 +167,30 @@ set_default_window_icon(PyObject UNUSED *self, PyObject *args) {
} }
static PyObject* static PyObject*
create_new_os_window(PyObject UNUSED *self, PyObject *args) { create_os_window(PyObject UNUSED *self, PyObject *args) {
int width, height; int width, height;
char *title; char *title;
if (!PyArg_ParseTuple(args, "iis", &width, &height, &title)) return NULL; if (!PyArg_ParseTuple(args, "iis", &width, &height, &title)) return NULL;
bool is_first_window = standard_cursor == NULL;
if (standard_cursor == NULL) { if (is_first_window) {
// The first window to be created
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_REQUIRED_VERSION_MAJOR); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, OPENGL_REQUIRED_VERSION_MAJOR);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_REQUIRED_VERSION_MINOR); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, OPENGL_REQUIRED_VERSION_MINOR);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, true);
glfwWindowHint(GLFW_SAMPLES, 0); glfwWindowHint(GLFW_SAMPLES, 0);
glfwSwapInterval(0); // a value of 1 makes mouse selection laggy
#ifdef __APPLE__ #ifdef __APPLE__
if (OPT(macos_hide_titlebar)) glfwWindowHint(GLFW_DECORATED, false); if (OPT(macos_hide_titlebar)) glfwWindowHint(GLFW_DECORATED, false);
// OS X cannot handle 16bit stencil buffers // OS X cannot handle 16bit stencil buffers
glfwWindowHint(GLFW_STENCIL_BITS, 8); glfwWindowHint(GLFW_STENCIL_BITS, 8);
#else
#endif #endif
standard_cursor = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR); standard_cursor = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
click_cursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR); click_cursor = glfwCreateStandardCursor(GLFW_HAND_CURSOR);
arrow_cursor = glfwCreateStandardCursor(GLFW_ARROW_CURSOR); arrow_cursor = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
if (standard_cursor == NULL || click_cursor == NULL || arrow_cursor == NULL) { 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) { 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); 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 (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(); OSWindow *w = add_os_window();
w->id = ++global_state.os_window_id_counter; w->id = ++global_state.os_window_id_counter;
glfwSetWindowUserPointer(glfw_window, w);
w->handle = glfw_window; 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); glfwSetCursor(glfw_window, standard_cursor);
w->viewport_size_dirty = true;
update_viewport(w); update_viewport(w);
glfwSetFramebufferSizeCallback(glfw_window, framebuffer_size_callback); glfwSetFramebufferSizeCallback(glfw_window, framebuffer_size_callback);
glfwSetCharModsCallback(glfw_window, char_mods_callback); glfwSetCharModsCallback(glfw_window, char_mods_callback);
@ -419,17 +424,6 @@ hide_mouse(OSWindow *w) {
glfwSetInputMode(w->handle, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); 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 void
swap_window_buffers(OSWindow *w) { swap_window_buffers(OSWindow *w) {
glfwSwapBuffers(w->handle); glfwSwapBuffers(w->handle);
@ -486,7 +480,7 @@ primary_monitor_content_scale(PyObject UNUSED *self) {
// Boilerplate {{{ // Boilerplate {{{
static PyMethodDef module_methods[] = { 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(set_default_window_icon, METH_VARARGS),
METHODB(get_clipboard_string, METH_NOARGS), METHODB(get_clipboard_string, METH_NOARGS),
METHODB(get_content_scale_for_window, METH_NOARGS), METHODB(get_content_scale_for_window, METH_NOARGS),

View File

@ -142,7 +142,7 @@ def run_app(opts, args):
set_scale(opts.box_drawing_scale) set_scale(opts.box_drawing_scale)
set_options(opts, iswayland, args.debug_gl) set_options(opts, iswayland, args.debug_gl)
load_cached_values() load_cached_values()
w, h = initial_window_size() w, h = initial_window_size(opts)
window_id = create_os_window(w, h, args.cls) window_id = create_os_window(w, h, args.cls)
startup_ctx = init_startup_notification(window_id) startup_ctx = init_startup_notification(window_id)
if isosx: if isosx:

View File

@ -425,22 +425,22 @@ KK5I(add_borders_rect)
static PyMethodDef module_methods[] = { static PyMethodDef module_methods[] = {
MW(current_os_window, METH_NOARGS), MW(current_os_window, METH_NOARGS),
MW(set_options, METH_O), MW(set_options, METH_VARARGS),
MW(handle_for_window_id, METH_VARARGS), MW(handle_for_window_id, METH_VARARGS),
MW(set_logical_dpi, METH_VARARGS), MW(set_logical_dpi, METH_VARARGS),
MW(add_tab, METH_O), MW(add_tab, METH_O),
MW(add_window, METH_VARARGS), MW(add_window, METH_VARARGS),
MW(update_window_title, METH_VARARGS), MW(update_window_title, METH_VARARGS),
MW(remove_tab, METH_O), MW(remove_tab, METH_VARARGS),
MW(remove_window, 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(set_active_window, METH_VARARGS),
MW(swap_tabs, METH_VARARGS), MW(swap_tabs, METH_VARARGS),
MW(swap_windows, METH_VARARGS), MW(swap_windows, METH_VARARGS),
MW(add_borders_rect, METH_VARARGS), MW(add_borders_rect, METH_VARARGS),
MW(set_tab_bar_render_data, METH_VARARGS), MW(set_tab_bar_render_data, METH_VARARGS),
MW(set_window_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(mark_os_window_for_close, METH_VARARGS),
MW(update_window_visibility, METH_VARARGS), MW(update_window_visibility, METH_VARARGS),
MW(set_boss, METH_O), MW(set_boss, METH_O),

View File

@ -148,7 +148,7 @@ ssize_t create_graphics_vao();
ssize_t create_border_vao(); ssize_t create_border_vao();
bool draw_cells(ssize_t, ssize_t, float, float, float, float, Screen *, OSWindow *); bool draw_cells(ssize_t, ssize_t, float, float, float, float, Screen *, OSWindow *);
void draw_cursor(CursorRenderInfo *, bool); void draw_cursor(CursorRenderInfo *, bool);
void update_viewport_size(int, int); void update_surface_size(int, int);
void free_texture(uint32_t*); void free_texture(uint32_t*);
void send_image_to_gpu(uint32_t*, const void*, int32_t, int32_t, bool, bool); 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*); void send_sprite_to_gpu(unsigned int, unsigned int, unsigned int, uint8_t*);