Skip to content

Commit a1a43a4

Browse files
authored
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
1 parent 3ab2acc commit a1a43a4

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/cascadia/TerminalControl/TermControl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,6 +3073,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
30733073
co_return;
30743074
}
30753075

3076+
if (const auto hwnd = reinterpret_cast<HWND>(OwningHwnd()))
3077+
{
3078+
SetForegroundWindow(hwnd);
3079+
}
3080+
30763081
const auto weak = get_weak();
30773082

30783083
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)