Skip to content

Commit 69b3e7a

Browse files
etbalaDHowett
authored andcommitted
Terminal receives focus on drag n drop (#20003)
### Summary Updates terminal to gain foreground focus when a user drags and drops a file into the terminal. ### Changes Updates the `DragDropHandler` to call `SetForegroundWindow`. ### Validation * Built and deployed locally * Manually verified terminal gains focus when dragging and dropping Closes #19934 (cherry picked from commit a1a43a4) Service-Card-Id: PVTI_lADOAF3p4s4BBcTlzgpBNEE Service-Version: 1.24
1 parent 8140092 commit 69b3e7a

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,6 +3198,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
31983198
co_return;
31993199
}
32003200

3201+
if (const auto hwnd = reinterpret_cast<HWND>(OwningHwnd()))
3202+
{
3203+
SetForegroundWindow(hwnd);
3204+
}
3205+
32013206
const auto weak = get_weak();
32023207

32033208
if (e.DataView().Contains(StandardDataFormats::ApplicationLink()))

src/interactivity/win32/windowproc.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,11 @@ LRESULT Window::_HandleGetDpiScaledSize(UINT dpiNew, _Inout_ SIZE* pSizeNew) con
963963
// - <none>
964964
void Window::_HandleDrop(const WPARAM wParam) const
965965
{
966+
if (const auto hwnd = GetWindowHandle())
967+
{
968+
SetForegroundWindow(hwnd);
969+
}
970+
966971
const auto drop = reinterpret_cast<HDROP>(wParam);
967972
Clipboard::Instance().PasteDrop(drop);
968973
DragFinish(drop);

0 commit comments

Comments
 (0)