From d35f91638a77531903e2323dc4664ae6d733a330 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Fri, 14 Feb 2025 17:57:46 +0200 Subject: [PATCH] Restore focus when exiting debugger --- debug.cpp | 1 + include/sysdeps.h | 3 ++- od-win32/writelog.cpp | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/debug.cpp b/debug.cpp index 8cdb1298..af2f366e 100644 --- a/debug.cpp +++ b/debug.cpp @@ -110,6 +110,7 @@ void deactivate_debugger (void) debugmem_enable(); debug_pc = 0xffffffff; keybuf_ignore_next_release(); + deactivate_console(); } void activate_debugger (void) diff --git a/include/sysdeps.h b/include/sysdeps.h index 97f24335..dae18aab 100644 --- a/include/sysdeps.h +++ b/include/sysdeps.h @@ -458,7 +458,8 @@ extern TCHAR *setconsolemode (TCHAR *buffer, int maxlen); extern void close_console (void); extern void open_console(void); extern void reopen_console(void); -extern void activate_console (void); +extern void activate_console(void); +extern void deactivate_console(void); extern void console_out (const TCHAR *); extern void console_out_f (const TCHAR *, ...); extern void console_flush (void); diff --git a/od-win32/writelog.cpp b/od-win32/writelog.cpp index 19b423e9..7e34b4dc 100644 --- a/od-win32/writelog.cpp +++ b/od-win32/writelog.cpp @@ -72,6 +72,7 @@ static int console_input_linemode = -1; int always_flush_log = 0; TCHAR *conlogfile = NULL; static FILE *conlogfilehandle; +static HWND previousactivewindow; #define WRITE_LOG_BUF_SIZE 4096 @@ -134,11 +135,21 @@ static void flushmsgpump(void) } } -void activate_console (void) +void deactivate_console(void) { + if (previousactivewindow) { + SetForegroundWindow(previousactivewindow); + previousactivewindow = NULL; + } +} + +void activate_console(void) +{ + previousactivewindow = NULL; if (!consoleopen) return; - SetForegroundWindow (GetConsoleWindow ()); + previousactivewindow = GetForegroundWindow(); + SetForegroundWindow(GetConsoleWindow()); } static void open_console_window (void) -- 2.47.3