can close windows independently

This commit is contained in:
Patedam committed 2026-10-25 15:57:52 -04:00
1 parent d2d9981efe
commit f580776964
2 files changed
+41

No files matched your search

+39
View File
@@ -38,10 +38,25 @@ internal void ja_frame()
{
for (WM_Event *event = events.first, *next = 0; event != 0; event = next)
{
JA_WindowState* ws = ja_window_state_from_platform_handle(event->window);
bool32 take = 0;
if (event->kind == WM_EventKind_WindowClose)
{
if (ws != 0)
{
JA_WindowRequest* request = ja_window_request_from_id(ws->id);
AssertAlways(request != 0);
ja_window_close_request(request);
if (ja_state->window_request_count == 0)
{
ja_state->quit = 1;
}
}
else
{
ja_state->quit = 1;
}
take = 1;
}
@@ -220,6 +235,23 @@ internal JA_WindowState* ja_window_state_from_id(JA_ID id)
return ws;
}
internal JA_WindowState* ja_window_state_from_platform_handle(WM_Window platform_handle)
{
JA_WindowState* ws = &ja_nil_window_state;
{
for (JA_WindowState* w_candidate = ja_state->first_window_state; w_candidate != &ja_nil_window_state;
w_candidate = w_candidate->order_next)
{
if (wm_window_match(w_candidate->plat_handle, platform_handle))
{
ws = w_candidate;
break;
}
}
}
return ws;
}
internal void ja_window_request()
{
JA_ID id = ja_state->window_request_gen_id++;
@@ -234,12 +266,16 @@ internal void ja_window_request()
}
result->id = id;
DLL_push_back(ja_state->window_request_first, ja_state->window_request_last, result);
ja_state->window_request_count += 1;
}
internal void ja_window_close_request(JA_WindowRequest* request)
{
DLL_remove(ja_state->window_request_first, ja_state->window_request_last, request);
SLL_stack_push(ja_state->free_window_request, request);
ja_state->window_request_count -= 1;
AssertAlways(ja_state->window_request_count >= 0);
}
internal JA_WindowRequest* ja_window_request_from_id(JA_ID id)
@@ -247,9 +283,12 @@ internal JA_WindowRequest* ja_window_request_from_id(JA_ID id)
JA_WindowRequest* result = 0;
for
EachNode(wr, JA_WindowRequest, ja_state->window_request_first)
{
if (wr->id == id)
{
result = wr;
break;
}
}
return result;
}
+2
View File
@@ -66,6 +66,7 @@ struct JA_State
JA_WindowRequest* window_request_first;
JA_WindowRequest* window_request_last;
JA_WindowRequest* free_window_request;
uint64 window_request_count;
// Windows
JA_WindowState* free_window_state;
@@ -100,6 +101,7 @@ internal void ja_id_list_push(Arena* arena, JA_IDList* list, JA_ID id);
// Window Functions
internal JA_WindowState* ja_window_state_from_id(JA_ID id);
internal JA_WindowState* ja_window_state_from_platform_handle(WM_Window platform_handle);
internal void ja_window_request();
internal void ja_window_close_request(JA_WindowRequest* request);
internal JA_WindowRequest* ja_window_request_from_id(JA_ID id);