diff --git a/include/ci2_window.h b/include/ci2_window.h index ba8530a..dd55a5c 100644 --- a/include/ci2_window.h +++ b/include/ci2_window.h @@ -25,6 +25,12 @@ SOFTWARE. #include "./base/ci2_base.h" +struct CI2_Window_Handle { + ci2_fd fd; + ci2_bool should_close; +}; +typedef struct CI2_Window_Handle CI2_Window_Handle; + // Opaque type for a window typedef struct CI2_Window CI2_Window; diff --git a/src/linux_ci2_window.c b/src/linux_ci2_window.c index 4770376..422434d 100644 --- a/src/linux_ci2_window.c +++ b/src/linux_ci2_window.c @@ -30,10 +30,9 @@ SOFTWARE. const ci2_sys_char *ci2_window_class = "Linux CI2 Window"; struct CI2_Window { + struct CI2_Window_Handle handle; Display* display; - Window window; Atom wm_delete_window; - ci2_bool should_close; }; ci2_bool ci2_init(void) { @@ -58,18 +57,19 @@ CI2_Window* ci2_create_window(const ci2_sys_char* title, int width, int height) XMapWindow(display, win); XFlush(display); + CI2_Window* window = malloc(sizeof(CI2_Window)); + // CI2_Window_Handle* h = malloc(sizeof(CI2_Window_Handle)); if (!window) { XDestroyWindow(display, win); XCloseDisplay(display); return NULL; } - + // window->handle = h; window->display = display; - window->window = win; window->wm_delete_window = wm_delete_window; - window->should_close = ci2_false; - + window->handle.should_close = ci2_false; + window->handle.fd = win; return window; } @@ -82,17 +82,17 @@ ci2_bool ci2_poll_events(CI2_Window* window) { if (event.type == ClientMessage && (Atom)event.xclient.data.l[0] == window->wm_delete_window) { - window->should_close = ci2_true; + window->handle.should_close = ci2_true; } } - return !window->should_close; + return !window->handle.should_close; } void ci2_destroy_window(CI2_Window* window) { if (!window) return; - XDestroyWindow(window->display, window->window); + XDestroyWindow(window->display, window->handle.fd); XCloseDisplay(window->display); free(window); } diff --git a/src/win32_ci2_window.c b/src/win32_ci2_window.c index 1c1d74f..4fb26b8 100644 --- a/src/win32_ci2_window.c +++ b/src/win32_ci2_window.c @@ -24,6 +24,7 @@ SOFTWARE. #include struct CI2_Window { + CI2_Window_Handle handle; HWND hwnd; ci2_bool should_close; }; @@ -69,12 +70,13 @@ CI2_Window* ci2_create_window(const ci2_sys_char* title, int width, int height) return NULL; } - window->hwnd = hwnd; - window->should_close = false; - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)window); + window->handle.fd = hwnd; + window->handle.should_close = ci2_false; + SetWindowLongPtr(window->handle.fd, GWLP_USERDATA, (LONG_PTR)window); - ShowWindow(window->hwnd, SW_SHOWNORMAL); - UpdateWindow(window->hwnd); + // Maybe? + ShowWindow(window->handle.fd, SW_SHOWNORMAL); + UpdateWindow(window->handle.fd); return window; } @@ -85,12 +87,12 @@ ci2_bool ci2_poll_events(CI2_Window* window) { TranslateMessage(&msg); DispatchMessage(&msg); } - return !window->should_close; + return !window->handle.should_close; } void ci2_destroy_window(CI2_Window* window) { if (!window) return; - DestroyWindow(window->hwnd); + DestroyWindow(window->handle.fd); free(window); } @@ -109,7 +111,7 @@ static LRESULT CALLBACK window_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM switch (uMsg) { case WM_CLOSE: - if (window) window->should_close = true; + if (window) window->handle.should_close = ci2_true; return 0; case WM_DESTROY: PostQuitMessage(0); diff --git a/tests/bin/01_ci2 b/tests/bin/01_ci2 new file mode 100755 index 0000000..9696b74 Binary files /dev/null and b/tests/bin/01_ci2 differ