From 2a8ca37cb30608886a22c4b6a49223b5832f34a3 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Mon, 15 Sep 2025 14:10:30 -0700 Subject: [PATCH] record & restore target window on runs --- src/os/gfx/linux/os_gfx_linux.c | 17 +++++++++++++++++ src/os/gfx/os_gfx.h | 6 ++++++ src/os/gfx/stub/os_gfx_stub.c | 17 +++++++++++++++++ src/os/gfx/win32/os_gfx_win32.c | 19 +++++++++++++++++++ src/radbin/radbin.c | 12 ++++++++++-- src/raddbg/raddbg_core.c | 7 +++++++ src/raddbg/raddbg_core.h | 3 +++ 7 files changed, 79 insertions(+), 2 deletions(-) diff --git a/src/os/gfx/linux/os_gfx_linux.c b/src/os/gfx/linux/os_gfx_linux.c index 12a9aa56..9485225b 100644 --- a/src/os/gfx/linux/os_gfx_linux.c +++ b/src/os/gfx/linux/os_gfx_linux.c @@ -327,6 +327,23 @@ os_dpi_from_window(OS_Handle handle) return 96.f; } +//////////////////////////////// +//~ rjf: @os_hooks External Windows (Implemented Per-OS) + +internal OS_Handle +os_focused_external_window(void) +{ + OS_Handle result = {0}; + // TODO(rjf) + return result; +} + +internal void +os_focus_external_window(OS_Handle handle) +{ + // TODO(rjf) +} + //////////////////////////////// //~ rjf: @os_hooks Monitors (Implemented Per-OS) diff --git a/src/os/gfx/os_gfx.h b/src/os/gfx/os_gfx.h index d56a71ca..8eabfd57 100644 --- a/src/os/gfx/os_gfx.h +++ b/src/os/gfx/os_gfx.h @@ -163,6 +163,12 @@ internal Rng2F32 os_rect_from_window(OS_Handle window); internal Rng2F32 os_client_rect_from_window(OS_Handle window); internal F32 os_dpi_from_window(OS_Handle window); +//////////////////////////////// +//~ rjf: @os_hooks External Windows (Implemented Per-OS) + +internal OS_Handle os_focused_external_window(void); +internal void os_focus_external_window(OS_Handle handle); + //////////////////////////////// //~ rjf: @os_hooks Monitors (Implemented Per-OS) diff --git a/src/os/gfx/stub/os_gfx_stub.c b/src/os/gfx/stub/os_gfx_stub.c index 3a095ab2..e1e9b805 100644 --- a/src/os/gfx/stub/os_gfx_stub.c +++ b/src/os/gfx/stub/os_gfx_stub.c @@ -149,6 +149,23 @@ os_dpi_from_window(OS_Handle window) return 96.f; } +//////////////////////////////// +//~ rjf: @os_hooks External Windows (Implemented Per-OS) + +internal OS_Handle +os_focused_external_window(void) +{ + OS_Handle result = {0}; + // TODO(rjf) + return result; +} + +internal void +os_focus_external_window(OS_Handle handle) +{ + // TODO(rjf) +} + //////////////////////////////// //~ rjf: @os_hooks Monitors (Implemented Per-OS) diff --git a/src/os/gfx/win32/os_gfx_win32.c b/src/os/gfx/win32/os_gfx_win32.c index dac8bde7..7874d97e 100644 --- a/src/os/gfx/win32/os_gfx_win32.c +++ b/src/os/gfx/win32/os_gfx_win32.c @@ -1367,6 +1367,25 @@ os_dpi_from_window(OS_Handle handle) return result; } +//////////////////////////////// +//~ rjf: @os_hooks External Windows (Implemented Per-OS) + +internal OS_Handle +os_focused_external_window(void) +{ + HWND hwnd = GetForegroundWindow(); + OS_Handle result = {(U64)hwnd}; + return result; +} + +internal void +os_focus_external_window(OS_Handle handle) +{ + HWND hwnd = (HWND)handle.u64[0]; + SetForegroundWindow(hwnd); + SetFocus(hwnd); +} + //////////////////////////////// //~ rjf: @os_hooks Monitors (Implemented Per-OS) diff --git a/src/radbin/radbin.c b/src/radbin/radbin.c index 1086608b..fc59c69c 100644 --- a/src/radbin/radbin.c +++ b/src/radbin/radbin.c @@ -999,7 +999,11 @@ rb_thread_entry_point(void *p) for(RB_FileNode *n = input_files.first; n != 0; n = n->next) { RB_File *f = n->v; - str8_list_pushf(arena, &output_blobs, "// %S (%S)\n\n", deterministic ? str8_skip_last_slash(f->path) : f->path, f->format ? rb_file_format_display_name_table[f->format] : str8_lit("Unsupported format")); + if(lane_idx() == 0) + { + str8_list_pushf(arena, &output_blobs, "// %S (%S)\n\n", deterministic ? str8_skip_last_slash(f->path) : f->path, f->format ? rb_file_format_display_name_table[f->format] : str8_lit("Unsupported format")); + } + lane_sync(); //- rjf: unpack file parses Arch arch = Arch_Null; @@ -1105,7 +1109,11 @@ rb_thread_entry_point(void *p) //- rjf: dump file extension info if(f->format_flags & RB_FileFormatFlag_HasDWARF) { - str8_list_pushf(arena, &output_blobs, "// %S (%S) (DWARF)\n\n", deterministic ? str8_skip_last_slash(f->path) : f->path, f->format ? rb_file_format_display_name_table[f->format] : str8_lit("Unsupported format")); + if(lane_idx() == 0) + { + str8_list_pushf(arena, &output_blobs, "// %S (%S) (DWARF)\n\n", deterministic ? str8_skip_last_slash(f->path) : f->path, f->format ? rb_file_format_display_name_table[f->format] : str8_lit("Unsupported format")); + } + lane_sync(); { String8List dump = dw_dump_list_from_sections(arena, &dw, arch, dw_dump_subset_flags); if(lane_idx() == 0) diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 21bec84a..e05c43d1 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -12807,6 +12807,12 @@ rd_frame(void) } } + // rjf: run -> refocus pre-stop focused window + if(kind == RD_CmdKind_Run) + { + os_focus_external_window(rd_state->prestop_focused_window); + } + // rjf: run -> no active targets, no processes, but we only have one target? -> just launch it, then select it if((kind == RD_CmdKind_Run || kind == RD_CmdKind_StepInto || @@ -17071,6 +17077,7 @@ rd_frame(void) } if(ws != &rd_nil_window_state) { + rd_state->prestop_focused_window = os_focused_external_window(); os_window_set_minimized(ws->os, 0); os_window_bring_to_front(ws->os); os_window_focus(ws->os); diff --git a/src/raddbg/raddbg_core.h b/src/raddbg/raddbg_core.h index 2cdcabc0..f56ec8ed 100644 --- a/src/raddbg/raddbg_core.h +++ b/src/raddbg/raddbg_core.h @@ -705,6 +705,9 @@ struct RD_State B32 bind_change_active; RD_CfgID bind_change_binding_id; String8 bind_change_cmd_name; + + // rjf: pre-stop focused window + OS_Handle prestop_focused_window; }; ////////////////////////////////