Skip to content

Commit 0252c78

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_lADOAF3p4s4BQX0-zgpBND8 Service-Version: 1.25
1 parent 82d5e0c commit 0252c78

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
@@ -3088,6 +3088,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
30883088
co_return;
30893089
}
30903090

3091+
if (const auto hwnd = reinterpret_cast<HWND>(OwningHwnd()))
3092+
{
3093+
SetForegroundWindow(hwnd);
3094+
}
3095+
30913096
const auto weak = get_weak();
30923097

30933098
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
@@ -951,6 +951,11 @@ LRESULT Window::_HandleGetDpiScaledSize(UINT dpiNew, _Inout_ SIZE* pSizeNew) con
951951
// - <none>
952952
void Window::_HandleDrop(const WPARAM wParam) const
953953
{
954+
if (const auto hwnd = GetWindowHandle())
955+
{
956+
SetForegroundWindow(hwnd);
957+
}
958+
954959
const auto drop = reinterpret_cast<HDROP>(wParam);
955960
Clipboard::Instance().PasteDrop(drop);
956961
DragFinish(drop);

0 commit comments

Comments
 (0)