Function to remove OSWindows
This commit is contained in:
parent
974950e7de
commit
eecd0c8d9a
@ -56,7 +56,7 @@ set_callback_window(GLFWwindow *w) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WINDOW_CALLBACK(name, fmt, ...) call_boss(name, "K" fmt, global_state.callback_os_window->window_id, __VA_ARGS__)
|
#define WINDOW_CALLBACK(name, fmt, ...) call_boss(name, "K" fmt, global_state.callback_os_window->id, __VA_ARGS__)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
framebuffer_size_callback(GLFWwindow *w, int width, int height) {
|
framebuffer_size_callback(GLFWwindow *w, int width, int height) {
|
||||||
@ -178,7 +178,7 @@ create_new_os_window(PyObject UNUSED *self, PyObject *args) {
|
|||||||
GLFWwindow *glfw_window = glfwCreateWindow(width, height, title, NULL, global_state.num_os_windows ? global_state.os_windows[0].handle : NULL);
|
GLFWwindow *glfw_window = glfwCreateWindow(width, height, title, NULL, global_state.num_os_windows ? global_state.os_windows[0].handle : NULL);
|
||||||
if (glfw_window == NULL) { Py_CLEAR(self); PyErr_SetString(PyExc_ValueError, "Failed to create GLFWwindow"); return NULL; }
|
if (glfw_window == NULL) { Py_CLEAR(self); PyErr_SetString(PyExc_ValueError, "Failed to create GLFWwindow"); return NULL; }
|
||||||
OSWindow *w = add_os_window();
|
OSWindow *w = add_os_window();
|
||||||
w->window_id = global_state.os_window_counter++;
|
w->id = global_state.os_window_counter++;
|
||||||
glfwSetWindowUserPointer(glfw_window, w);
|
glfwSetWindowUserPointer(glfw_window, w);
|
||||||
w->handle = glfw_window;
|
w->handle = glfw_window;
|
||||||
glfwSetCursor(glfw_window, standard_cursor);
|
glfwSetCursor(glfw_window, standard_cursor);
|
||||||
@ -200,7 +200,7 @@ create_new_os_window(PyObject UNUSED *self, PyObject *args) {
|
|||||||
w->is_focused = true;
|
w->is_focused = true;
|
||||||
w->cursor_blink_zero_time = now;
|
w->cursor_blink_zero_time = now;
|
||||||
w->last_mouse_activity_at = now;
|
w->last_mouse_activity_at = now;
|
||||||
return PyLong_FromUnsignedLongLong(w->window_id);
|
return PyLong_FromUnsignedLongLong(w->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Global functions {{{
|
// Global functions {{{
|
||||||
|
|||||||
@ -9,11 +9,8 @@
|
|||||||
|
|
||||||
GlobalState global_state = {{0}};
|
GlobalState global_state = {{0}};
|
||||||
|
|
||||||
#define ensure_can_add(array, count, msg) if (count >= sizeof(array)/sizeof(array[0]) - 1) fatal(msg);
|
|
||||||
|
|
||||||
#define noop(...)
|
#define noop(...)
|
||||||
#define REMOVER(array, qid, count, structure, destroy) { \
|
#define REMOVER(array, qid, count, structure, destroy, capacity) { \
|
||||||
size_t capacity = sizeof(array)/sizeof(array[0]); \
|
|
||||||
for (size_t i = 0; i < count; i++) { \
|
for (size_t i = 0; i < count; i++) { \
|
||||||
if (array[i].id == qid) { \
|
if (array[i].id == qid) { \
|
||||||
destroy(array[i]); \
|
destroy(array[i]); \
|
||||||
@ -26,13 +23,13 @@ GlobalState global_state = {{0}};
|
|||||||
#define WITH_OS_WINDOW(os_window_id) \
|
#define WITH_OS_WINDOW(os_window_id) \
|
||||||
for (size_t o = 0; o < global_state.num_os_windows; o++) { \
|
for (size_t o = 0; o < global_state.num_os_windows; o++) { \
|
||||||
OSWindow *os_window = global_state.os_windows + o; \
|
OSWindow *os_window = global_state.os_windows + o; \
|
||||||
if (os_window->window_id == os_window_id) {
|
if (os_window->id == os_window_id) {
|
||||||
#define END_WITH_OS_WINDOW break; }}
|
#define END_WITH_OS_WINDOW break; }}
|
||||||
|
|
||||||
#define WITH_TAB(os_window_id, tab_id) \
|
#define WITH_TAB(os_window_id, tab_id) \
|
||||||
for (size_t o = 0; o < global_state.num_os_windows; o++) { \
|
for (size_t o = 0; o < global_state.num_os_windows; o++) { \
|
||||||
OSWindow *osw = global_state.os_windows + o; \
|
OSWindow *osw = global_state.os_windows + o; \
|
||||||
if (osw->window_id == os_window_id) { \
|
if (osw->id == os_window_id) { \
|
||||||
for (size_t t = 0; t < osw->num_tabs; t++) { \
|
for (size_t t = 0; t < osw->num_tabs; t++) { \
|
||||||
if (osw->tabs[t].id == tab_id) { \
|
if (osw->tabs[t].id == tab_id) { \
|
||||||
Tab *tab = osw->tabs + t;
|
Tab *tab = osw->tabs + t;
|
||||||
@ -104,10 +101,17 @@ update_window_title(id_type os_window_id, id_type tab_id, id_type window_id, PyO
|
|||||||
END_WITH_TAB;
|
END_WITH_TAB;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void
|
||||||
|
remove_os_window(id_type os_window_id) {
|
||||||
|
#define destroy_window(w) Py_CLEAR(w.window_title); Py_CLEAR(w.tab_bar_render_data.screen);
|
||||||
|
REMOVER(global_state.os_windows, os_window_id, global_state.num_os_windows, OSWindow, destroy_window, global_state.capacity);
|
||||||
|
#undef destroy_window
|
||||||
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
remove_tab(id_type os_window_id, id_type id) {
|
remove_tab(id_type os_window_id, id_type id) {
|
||||||
WITH_OS_WINDOW(os_window_id)
|
WITH_OS_WINDOW(os_window_id)
|
||||||
REMOVER(os_window->tabs, id, os_window->num_tabs, Tab, noop);
|
REMOVER(os_window->tabs, id, os_window->num_tabs, Tab, noop, os_window->capacity);
|
||||||
END_WITH_OS_WINDOW
|
END_WITH_OS_WINDOW
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +119,7 @@ static inline void
|
|||||||
remove_window(id_type os_window_id, id_type tab_id, id_type id) {
|
remove_window(id_type os_window_id, id_type tab_id, id_type id) {
|
||||||
WITH_TAB(os_window_id, tab_id);
|
WITH_TAB(os_window_id, tab_id);
|
||||||
#define destroy_window(w) Py_CLEAR(w.render_data.screen); Py_CLEAR(w.title);
|
#define destroy_window(w) Py_CLEAR(w.render_data.screen); Py_CLEAR(w.title);
|
||||||
REMOVER(tab->windows, id, tab->num_windows, Window, destroy_window);
|
REMOVER(tab->windows, id, tab->num_windows, Window, destroy_window, tab->capacity);
|
||||||
#undef destroy_window
|
#undef destroy_window
|
||||||
END_WITH_TAB;
|
END_WITH_TAB;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -72,7 +72,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *handle;
|
void *handle;
|
||||||
id_type window_id;
|
id_type id;
|
||||||
OSWindowGeometry before_fullscreen;
|
OSWindowGeometry before_fullscreen;
|
||||||
int viewport_width, viewport_height;
|
int viewport_width, viewport_height;
|
||||||
double viewport_x_ratio, viewport_y_ratio;
|
double viewport_x_ratio, viewport_y_ratio;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user