Linux window handle

This commit is contained in:
2026-05-11 18:43:11 -05:00
parent 71a5964041
commit a952b94a15
4 changed files with 25 additions and 17 deletions

View File

@@ -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;

View File

@@ -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);
}

View File

@@ -24,6 +24,7 @@ SOFTWARE.
#include <stdlib.h>
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);

BIN
tests/bin/01_ci2 Executable file

Binary file not shown.