Skip to content

Terminal receives focus on drag n drop - #20003

Merged
carlos-zamora merged 2 commits into
microsoft:mainfrom
etbala:main
Mar 27, 2026
Merged

Terminal receives focus on drag n drop#20003
carlos-zamora merged 2 commits into
microsoft:mainfrom
etbala:main

Conversation

@etbala

@etbala etbala commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #19934

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


if (const auto hwnd = reinterpret_cast<HWND>(OwningHwnd()))
{
SetForegroundWindow(hwnd);

@lhecker lhecker Mar 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind also adding this here?

void Window::_HandleDrop(const WPARAM wParam) const
{
const auto drop = reinterpret_cast<HDROP>(wParam);
Clipboard::Instance().PasteDrop(drop);
DragFinish(drop);
}

Something like this:

if (const auto hwnd = GetWindowHandle())
{
    SetForegroundWindow(hwnd);
}

This way, even the old conhost (the classic console window) would get this improvement. You can test conhost by setting Conhost\Host.EXE as your startup project.

...I'm not sure if it'll work though, given that it relies on WM_DROPFILES and not OLE.

Thank you for working on this!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added! Looks like it was just as easy as calling SetForegroundWindow again.

@etbala

etbala commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@carlos-zamora carlos-zamora left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Tested on Windows Terminal and Conhost

Thank you so much for doing this! 🙏

@carlos-zamora

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@carlos-zamora
carlos-zamora enabled auto-merge (squash) March 27, 2026 21:15
@DHowett

DHowett commented Mar 27, 2026

Copy link
Copy Markdown
Member

I'm a little hesitant to put TermControl--which is supposed to know only XAML and nothing of the window outside of it--in charge of this... but I'll probably let it slide for now and fix it when I move drag/drop up into TerminalApp.

@DHowett

DHowett commented Mar 27, 2026

Copy link
Copy Markdown
Member

(thanks for the fix!)

@carlos-zamora
carlos-zamora merged commit a1a43a4 into microsoft:main Mar 27, 2026
14 of 16 checks passed
@github-project-automation github-project-automation Bot moved this to To Cherry Pick in 1.25 Servicing Pipeline Apr 3, 2026
@github-project-automation github-project-automation Bot moved this to To Cherry Pick in 1.24 Servicing Pipeline Apr 3, 2026
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.25 Servicing Pipeline Apr 3, 2026
DHowett pushed a commit that referenced this pull request Apr 3, 2026
### 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
ulfschnabel pushed a commit to ulfschnabel/terminal that referenced this pull request Apr 12, 2026
### 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 microsoft#19934
@DHowett DHowett moved this from To Cherry Pick to Cherry Picked in 1.24 Servicing Pipeline Apr 30, 2026
DHowett pushed a commit that referenced this pull request Apr 30, 2026
### 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
@DHowett DHowett moved this from Cherry Picked to Shipped in 1.25 Servicing Pipeline Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Cherry Picked

Development

Successfully merging this pull request may close these issues.

Terminal should automatically receive focus after dragging and dropping files

4 participants