From 4f99a76acea8ce8a929960d5e88468fd4642deca Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Fri, 21 Feb 2025 10:57:32 -0800 Subject: [PATCH] commit window placement/etc. to cfg tree, pass through all monitor/pos/size/fullscreen/maximize info to initialization --- src/os/gfx/linux/os_gfx_linux.c | 4 +- src/os/gfx/os_gfx.h | 5 +- src/os/gfx/stub/os_gfx_stub.c | 2 +- src/os/gfx/win32/os_gfx_win32.c | 12 ++-- src/raddbg/raddbg_core.c | 103 +++++++++++++++++++++++++++++++- 5 files changed, 116 insertions(+), 10 deletions(-) diff --git a/src/os/gfx/linux/os_gfx_linux.c b/src/os/gfx/linux/os_gfx_linux.c index b2b08312..be83091f 100644 --- a/src/os/gfx/linux/os_gfx_linux.c +++ b/src/os/gfx/linux/os_gfx_linux.c @@ -71,8 +71,10 @@ os_get_clipboard_text(Arena *arena) //~ rjf: @os_hooks Windows (Implemented Per-OS) internal OS_Handle -os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title) +os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title) { + Vec2F32 resolution = dim_2f32(rect); + //- rjf: allocate window OS_LNX_Window *w = os_lnx_gfx_state->free_window; if(w) diff --git a/src/os/gfx/os_gfx.h b/src/os/gfx/os_gfx.h index c0ddb4ea..9c50c5d3 100644 --- a/src/os/gfx/os_gfx.h +++ b/src/os/gfx/os_gfx.h @@ -21,7 +21,8 @@ struct OS_GfxInfo typedef U32 OS_WindowFlags; enum { - OS_WindowFlag_CustomBorder = (1<<0), + OS_WindowFlag_CustomBorder = (1<<0), + OS_WindowFlag_UseDefaultPosition = (1<<1), }; //////////////////////////////// @@ -139,7 +140,7 @@ internal String8 os_get_clipboard_text(Arena *arena); //////////////////////////////// //~ rjf: @os_hooks Windows (Implemented Per-OS) -internal OS_Handle os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title); +internal OS_Handle os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title); internal void os_window_close(OS_Handle window); internal void os_window_first_paint(OS_Handle window); internal void os_window_focus(OS_Handle window); diff --git a/src/os/gfx/stub/os_gfx_stub.c b/src/os/gfx/stub/os_gfx_stub.c index fc481446..66b3f898 100644 --- a/src/os/gfx/stub/os_gfx_stub.c +++ b/src/os/gfx/stub/os_gfx_stub.c @@ -34,7 +34,7 @@ os_get_clipboard_text(Arena *arena) //~ rjf: @os_hooks Windows (Implemented Per-OS) internal OS_Handle -os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title) +os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title) { OS_Handle handle = {1}; return handle; diff --git a/src/os/gfx/win32/os_gfx_win32.c b/src/os/gfx/win32/os_gfx_win32.c index fdcac746..4e8daab1 100644 --- a/src/os/gfx/win32/os_gfx_win32.c +++ b/src/os/gfx/win32/os_gfx_win32.c @@ -1015,9 +1015,12 @@ os_get_clipboard_text(Arena *arena) //~ rjf: @os_hooks Windows (Implemented Per-OS) internal OS_Handle -os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title) +os_window_open(Rng2F32 rect, OS_WindowFlags flags, String8 title) { B32 custom_border = !!(flags & OS_WindowFlag_CustomBorder); + B32 use_default_position = !!(flags & OS_WindowFlag_UseDefaultPosition); + Vec2F32 pos = rect.p0; + Vec2F32 dim = dim_2f32(rect); //- rjf: make hwnd HWND hwnd = 0; @@ -1029,9 +1032,10 @@ os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title) L"graphical-window", (WCHAR*)title16.str, WS_OVERLAPPEDWINDOW | WS_SIZEBOX, - CW_USEDEFAULT, CW_USEDEFAULT, - (int)resolution.x, - (int)resolution.y, + use_default_position ? CW_USEDEFAULT : (S32)pos.x, + use_default_position ? CW_USEDEFAULT : (S32)pos.y, + (S32)dim.x, + (S32)dim.y, 0, 0, os_w32_gfx_state->hInstance, 0); diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 5d899a55..2c5282c1 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -5972,11 +5972,17 @@ rd_window_state_from_cfg(RD_Cfg *cfg) Temp scratch = scratch_begin(0, 0); // rjf: unpack configuration options + B32 has_pos = 0; + Vec2F32 pos = {0}; Vec2F32 size = {0}; OS_Handle preferred_monitor = {0}; { + RD_Cfg *pos_cfg = rd_cfg_child_from_string(window_cfg, str8_lit("pos")); + has_pos = (pos_cfg != &rd_nil_cfg); RD_Cfg *size_cfg = rd_cfg_child_from_string(window_cfg, str8_lit("size")); RD_Cfg *monitor_cfg = rd_cfg_child_from_string(window_cfg, str8_lit("monitor")); + pos.x = (F32)f64_from_str8(pos_cfg->first->string); + pos.y = (F32)f64_from_str8(pos_cfg->first->next->string); size.x = (F32)f64_from_str8(size_cfg->first->string); size.y = (F32)f64_from_str8(size_cfg->first->next->string); OS_HandleArray monitors = os_push_monitors_array(scratch.arena); @@ -6008,7 +6014,7 @@ rd_window_state_from_cfg(RD_Cfg *cfg) ws->arena = arena_alloc(); { String8 title = str8_lit_comp(BUILD_TITLE_STRING_LITERAL); - ws->os = os_window_open(size, OS_WindowFlag_CustomBorder, title); + ws->os = os_window_open(r2f32p(pos.x, pos.y, pos.x+size.x, pos.y+size.y), (!has_pos*OS_WindowFlag_UseDefaultPosition)|OS_WindowFlag_CustomBorder, title); } ws->r = r_window_equip(ws->os); ws->ui = ui_state_alloc(); @@ -6264,6 +6270,94 @@ rd_window_frame(void) } } + ////////////////////////////// + //- rjf: commit window's position/status to underlying cfg tree + // + { + Temp scratch = scratch_begin(0, 0); + B32 is_fullscreen = os_window_is_fullscreen(ws->os); + B32 is_maximized = os_window_is_maximized(ws->os); + if(is_fullscreen) + { + rd_cfg_child_from_string_or_alloc(window, str8_lit("fullscreen")); + } + else + { + rd_cfg_release(rd_cfg_child_from_string(window, str8_lit("fullscreen"))); + } + if(is_maximized) + { + rd_cfg_child_from_string_or_alloc(window, str8_lit("maximized")); + } + else + { + rd_cfg_release(rd_cfg_child_from_string(window, str8_lit("maximized"))); + } + + //- rjf: commit position + Rng2F32 window_rect = os_rect_from_window(ws->os); + if(!is_fullscreen && !is_maximized) + { + Vec2F32 pos = window_rect.p0; + RD_Cfg *pos_root = rd_cfg_child_from_string_or_alloc(window, str8_lit("pos")); + if((S32)pos.x != (S32)f64_from_str8(pos_root->first->string) || + (S32)pos.y != (S32)f64_from_str8(pos_root->last->string)) + { + RD_Cfg *x = pos_root->first; + if(x == &rd_nil_cfg) + { + x= rd_cfg_alloc(); + rd_cfg_insert_child(pos_root, &rd_nil_cfg, x); + } + RD_Cfg *y = x->next; + if(y == &rd_nil_cfg) + { + y = rd_cfg_alloc(); + rd_cfg_insert_child(pos_root, x, y); + } + rd_cfg_equip_stringf(x, "%i", (S32)pos.x); + rd_cfg_equip_stringf(y, "%i", (S32)pos.y); + } + } + + //- rjf: commit size + if(!is_fullscreen && !is_maximized) + { + Vec2F32 size = dim_2f32(window_rect); + RD_Cfg *size_root = rd_cfg_child_from_string_or_alloc(window, str8_lit("size")); + if((S32)size.x != (S32)f64_from_str8(size_root->first->string) || + (S32)size.y != (S32)f64_from_str8(size_root->last->string)) + { + RD_Cfg *width = size_root->first; + if(width == &rd_nil_cfg) + { + width = rd_cfg_alloc(); + rd_cfg_insert_child(size_root, &rd_nil_cfg, width); + } + RD_Cfg *height = width->next; + if(height == &rd_nil_cfg) + { + height = rd_cfg_alloc(); + rd_cfg_insert_child(size_root, width, height); + } + rd_cfg_equip_stringf(width, "%i", (S32)size.x); + rd_cfg_equip_stringf(height, "%i", (S32)size.y); + } + } + + //- rjf: commit monitor + { + OS_Handle monitor = os_monitor_from_window(ws->os); + String8 monitor_name = os_name_from_monitor(scratch.arena, monitor); + RD_Cfg *monitor_root = rd_cfg_child_from_string_or_alloc(window, str8_lit("monitor")); + if(!str8_match(monitor_root->first->string, monitor_name, 0)) + { + rd_cfg_new_replace(monitor_root, monitor_name); + } + } + scratch_end(scratch); + } + ////////////////////////////// //- rjf: fill panel/view interaction registers // @@ -13616,7 +13710,11 @@ rd_frame(void) for(RD_Cfg *old_child = old_window->first; old_child != &rd_nil_cfg; old_child = old_child->next) { if(!str8_match(old_child->string, str8_lit("panels"), 0) && - !str8_match(old_child->string, str8_lit("size"), 0)) + !str8_match(old_child->string, str8_lit("size"), 0) && + !str8_match(old_child->string, str8_lit("pos"), 0) && + !str8_match(old_child->string, str8_lit("monitor"), 0) && + !str8_match(old_child->string, str8_lit("fullscreen"), 0) && + !str8_match(old_child->string, str8_lit("maximized"), 0)) { RD_Cfg *new_child = rd_cfg_deep_copy(old_child); rd_cfg_insert_child(new_window, new_window->last, new_child); @@ -16048,6 +16146,7 @@ Z(getting_started) String8 file_path = rd_regs()->file_path; RD_Cfg *project = rd_cfg_child_from_string(rd_state->root_cfg, str8_lit("project")); RD_Cfg *target = rd_cfg_new(project, str8_lit("target")); + rd_cfg_new(target, str8_lit("disabled")); RD_Cfg *exe = rd_cfg_new(target, str8_lit("executable")); rd_cfg_new(exe, file_path); String8 working_directory = str8_chop_last_slash(file_path);