From 7a5f22cfe87f938ef58f92b48ac379dc1c4c81c7 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Fri, 10 May 2024 11:21:56 -0400 Subject: add upstream 13.6 --- wx+/window_tools.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'wx+/window_tools.h') diff --git a/wx+/window_tools.h b/wx+/window_tools.h index 19b89176..94cb2c32 100644 --- a/wx+/window_tools.h +++ b/wx+/window_tools.h @@ -54,6 +54,15 @@ wxTopLevelWindow* getTopLevelWindow(wxWindow* child) even if the user is currently busy using a different app! More curiosity: this foreground focus stealing happens only during the *first* SetFocus() after app start! It also can be avoided by changing focus back and forth with some other app after start => wxWidgets bug or Win32 feature??? */ +inline +void setFocusIfActive(wxWindow& win) //don't steal keyboard focus when currently using a different foreground application +{ + if (wxTopLevelWindow* topWin = getTopLevelWindow(&win)) + if (topWin->IsActive()) //Linux/macOS: already behaves just like ::GetForegroundWindow() on Windows! + win.SetFocus(); +} + + struct FocusPreserver { FocusPreserver() @@ -70,9 +79,7 @@ struct FocusPreserver if (oldFocusId_ != wxID_ANY) if (wxWindow* oldFocusWin = wxWindow::FindWindowById(oldFocusId_)) - if (wxTopLevelWindow* topWin = getTopLevelWindow(oldFocusWin)) - if (topWin->IsActive()) //Linux/macOS: already behaves just like ::GetForegroundWindow() on Windows! - oldFocusWin->SetFocus(); + setFocusIfActive(*oldFocusWin); } wxWindowID getFocusId() const { return oldFocusId_; } -- cgit