microsoft / microsoft/terminal

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

Open
#13,525 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area-Server Issue-Bug Product-Conpty
Dominant language
C++
Stars
105k
Forks
9.6k
Avg merge
3d 17h
Merged PRs (30d)
29

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the supplied CUI examples, starting from the pseudoconsole hosting window behavior observed through GetConsoleWindow and GetWindowRect. Verify the hosting window's position and size while Terminal is moved across monitors; done means those values match the Terminal window so dialogs and message boxes open on the correct display.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.