Function to remove OSWindows
This commit is contained in:
parent
974950e7de
commit
eecd0c8d9a
@ -56,7 +56,7 @@ set_callback_window(GLFWwindow *w) {
|
||||
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
|
||||
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);
|
||||
if (glfw_window == NULL) { Py_CLEAR(self); PyErr_SetString(PyExc_ValueError, "Failed to create GLFWwindow"); return NULL; }
|
||||
OSWindow *w = add_os_window();
|
||||
w->window_id = global_state.os_window_counter++;
|
||||
w->id = global_state.os_window_counter++;
|
||||
glfwSetWindowUserPointer(glfw_window, w);
|
||||
w->handle = glfw_window;
|
||||
glfwSetCursor(glfw_window, standard_cursor);
|
||||
@ -200,7 +200,7 @@ create_new_os_window(PyObject UNUSED *self, PyObject *args) {
|
||||
w->is_focused = true;
|
||||
w->cursor_blink_zero_time = now;
|
||||
w->last_mouse_activity_at = now;
|
||||
return PyLong_FromUnsignedLongLong(w->window_id);
|
||||
return PyLong_FromUnsignedLongLong(w->id);
|
||||
}
|
||||
|
||||
// Global functions {{{
|
||||
|
||||
@ -9,11 +9,8 @@
|
||||
|
||||
GlobalState global_state = {{0}};
|
||||
|
||||
#define ensure_can_add(array, count, msg) if (count >= sizeof(array)/sizeof(array[0]) - 1) fatal(msg);
|
||||
|
||||
#define noop(...)
|
||||
#define REMOVER(array, qid, count, structure, destroy) { \
|
||||
size_t capacity = sizeof(array)/sizeof(array[0]); \
|
||||
#define REMOVER(array, qid, count, structure, destroy, capacity) { \
|
||||
for (size_t i = 0; i < count; i++) { \
|
||||
if (array[i].id == qid) { \
|
||||
destroy(array[i]); \
|
||||
@ -26,13 +23,13 @@ GlobalState global_state = {{0}};
|
||||
#define WITH_OS_WINDOW(os_window_id) \
|
||||
for (size_t o = 0; o < global_state.num_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 WITH_TAB(os_window_id, tab_id) \
|
||||
for (size_t o = 0; o < global_state.num_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++) { \
|
||||
if (osw->tabs[t].id == tab_id) { \
|
||||
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;
|
||||
}
|
||||
|
||||
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
|
||||
remove_tab(id_type os_window_id, id_type 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
|
||||
}
|
||||
|
||||
@ -115,7 +119,7 @@ static inline void
|
||||
remove_window(id_type os_window_id, id_type tab_id, id_type id) {
|
||||
WITH_TAB(os_window_id, tab_id);
|
||||
#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
|
||||
END_WITH_TAB;
|
||||
}
|
||||
|
||||
@ -72,7 +72,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
void *handle;
|
||||
id_type window_id;
|
||||
id_type id;
|
||||
OSWindowGeometry before_fullscreen;
|
||||
int viewport_width, viewport_height;
|
||||
double viewport_x_ratio, viewport_y_ratio;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user