Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pseudoconsole hosting window position and size do not match the Terminal window #13525

Open
Tracked by #13392
PhMajerus opened this issue Jul 17, 2022 · 2 comments
Open
Tracked by #13392
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Conpty For console issues specifically related to conpty

Comments

@PhMajerus
Copy link

PhMajerus commented Jul 17, 2022

Windows Terminal version

1.15.1863.0 (preview)

Windows build number

10.0.22621.232

Other Software

All Win32 CUI apps that use GUI windows (incl. popups and dialogs) with the console as the parent.

Steps to reproduce

So ConPTY now has pseudoconsole hosting windows for Win32 CUI apps to be able to get a handle using GetConsoleWindow and support some of the scenarios expected from a Windows console host.

A common scenario is for a CUI app to use some GUI elements such as messageboxes and dialogs, using the console HWND as the parent.
Messageboxes as well as dialogs with the DS_CENTER flag automatically get centered on the monitor containing the parent window. Many apps will go further and try to center their dialogs over their parent window.
This is important on multi-monitors system to have the new window visibly related to its parent instead of in the center of the primary/main display, making it easier to find or even to notice. It also improves productivity by minimizing the pointer movements required to reach related UI.

See for example the following code:

#include <Windows.h>

int main()
{
    HWND hwndParent = GetConsoleWindow();
    MessageBox(hwndParent, TEXT("This dialog should be centered on the screen where the console is."), TEXT("Demo dialog from CUI app"), MB_OK);
}

Currently, this works when using the legacy console as its window is properly positioned and sized, but always get displayed on the primary/main monitor when using the Terminal.

When using Terminal, the pseudoconsole hosting window is always located at 0,0 and sized 16,16.

This can be tested with the following code:

#include <Windows.h>
#include <stdio.h>

int main()
{
    HWND hwndParent = GetConsoleWindow();

    RECT rc;
    GetWindowRect(hwndParent, &rc);
    printf("coordinates %d,%d,%d,%d\r\n", rc.left, rc.top, rc.right, rc.bottom);
}

This makes screen-centered messageboxes and dialogs centered in the primary/main display instead of on the monitor where the Terminal is.
Even worse, some apps trying to center their dialogs over their parent window do not handle desktop boundaries and will clip their dialogs by centering them at 8,8, making it difficult even to move them into view since their title bars are offscreen (unless user has negative coordinates monitors as part of their desktop).

Expected Behavior

Pseudoconsole hosting windows should be moved and sized to always match the Terminal window, so that apps relying on GetWindowRect get valid values. Note even the dialog manager and the MessageBox function are using those values to center popups and dialogs on the same display.

Actual Behavior

CUI apps relying on pseudoconsole hosting windows positions and sizes will not display messageboxes and dialogs in their intended location, and sometimes even partially offscreen.

@PhMajerus PhMajerus added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Jul 17, 2022
@ghost ghost added Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jul 17, 2022
@zadjii-msft zadjii-msft added the Needs-Discussion Something that requires a team discussion before we can proceed label Jul 19, 2022
@Lo0oG
Copy link

Lo0oG commented Jul 19, 2022

The following powershell script will also demonstrate the issue when you have multiple monitors. The message box will always be displayed on the primary monitor with Terminal whereas the legacy console will show the message box on the same window as the console.

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms");[System.Windows.Forms.Messagebox]::Show("Test")

@carlos-zamora carlos-zamora added Product-Conpty For console issues specifically related to conpty Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements Needs-Discussion Something that requires a team discussion before we can proceed labels Oct 4, 2022
@carlos-zamora
Copy link
Member

Sorry for the radio silence here. Finally got a chance to talk about it as a team. This is something we definitely need a solution for, but we need to write a big spec for it considering that Windows Terminal supports panes and tabs (so that complicates things). Tagging up appropriately and throwing it in the "up next" milestone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Conpty For console issues specifically related to conpty
Projects
None yet
Development

No branches or pull requests

4 participants