Lots of work is duplicated when NonClientIslandWindow is resized and the drag bar size changes #2669

Closed
opened 2026-01-30 23:01:50 +00:00 by claunia · 3 comments
Owner

Originally created by @zadjii-msft on GitHub (Jul 9, 2019).

Originally assigned to: @zadjii-msft on GitHub.

This is work that's following on from work that's being done for #1625.

I'm pulling the code for updating the drag region out of NonClientIslandWindow::OnSize into its own method. Unfortunately, both these methods need to do the following block of work:


        const auto windowRect = GetWindowRect();
        const auto width = windowRect.right - windowRect.left;
        const auto height = windowRect.bottom - windowRect.top;

        const auto scale = GetCurrentDpiScale();
        const auto dpi = ::GetDpiForWindow(_window.get());

        const auto dragY = ::GetSystemMetricsForDpi(SM_CYDRAG, dpi);
        const auto dragX = ::GetSystemMetricsForDpi(SM_CXDRAG, dpi);

        // If we're maximized, we don't want to use the frame as our margins,
        // instead we want to use the margins from the maximization. If we included
        // the left&right sides of the frame in this calculation while maximized,
        // you' have a few pixels of the window border on the sides while maximized,
        // which most apps do not have.
        const auto bordersWidth = _isMaximized ?
                                      (_maximizedMargins.cxLeftWidth + _maximizedMargins.cxRightWidth) :
                                      (dragX * 2);
        const auto bordersHeight = _isMaximized ?
                                       (_maximizedMargins.cyBottomHeight + _maximizedMargins.cyTopHeight) :
                                       (dragY * 2);

        const auto windowsWidth = width - bordersWidth;
        const auto windowsHeight = height - bordersHeight;
        const auto xPos = _isMaximized ? _maximizedMargins.cxLeftWidth : dragX;
        const auto yPos = _isMaximized ? _maximizedMargins.cyTopHeight : dragY;

        const auto dragBarRect = GetDragAreaRect();
        const auto nonClientHeight = dragBarRect.bottom - dragBarRect.top;

Doing this twice is clearly ridiculous, and more likely than not, wrong.

I'm thinking that on the resize, we could probably just cache some of these values. I think this will also important for dealing with maximizing, cause I think know the maximize borders are wrong on non-primary displays.

Originally created by @zadjii-msft on GitHub (Jul 9, 2019). Originally assigned to: @zadjii-msft on GitHub. This is work that's following on from work that's being done for #1625. I'm pulling the code for updating the drag region out of `NonClientIslandWindow::OnSize` into its own method. Unfortunately, both these methods need to do the following block of work: ```c++ const auto windowRect = GetWindowRect(); const auto width = windowRect.right - windowRect.left; const auto height = windowRect.bottom - windowRect.top; const auto scale = GetCurrentDpiScale(); const auto dpi = ::GetDpiForWindow(_window.get()); const auto dragY = ::GetSystemMetricsForDpi(SM_CYDRAG, dpi); const auto dragX = ::GetSystemMetricsForDpi(SM_CXDRAG, dpi); // If we're maximized, we don't want to use the frame as our margins, // instead we want to use the margins from the maximization. If we included // the left&right sides of the frame in this calculation while maximized, // you' have a few pixels of the window border on the sides while maximized, // which most apps do not have. const auto bordersWidth = _isMaximized ? (_maximizedMargins.cxLeftWidth + _maximizedMargins.cxRightWidth) : (dragX * 2); const auto bordersHeight = _isMaximized ? (_maximizedMargins.cyBottomHeight + _maximizedMargins.cyTopHeight) : (dragY * 2); const auto windowsWidth = width - bordersWidth; const auto windowsHeight = height - bordersHeight; const auto xPos = _isMaximized ? _maximizedMargins.cxLeftWidth : dragX; const auto yPos = _isMaximized ? _maximizedMargins.cyTopHeight : dragY; const auto dragBarRect = GetDragAreaRect(); const auto nonClientHeight = dragBarRect.bottom - dragBarRect.top; ``` Doing this twice is clearly ridiculous, and more likely than not, _wrong_. I'm thinking that on the resize, we could _probably_ just cache some of these values. I think this will also important for dealing with maximizing, cause I ~~think~~ know the maximize borders are wrong on non-primary displays.
Author
Owner

@Insomniak47 commented on GitHub (Jul 13, 2019):

Just wanted to pop in and confirm that your intuition re: Maximizing on non-primary windows is correct:
I've got a portrait mode 1920*1080 monitor and when I maximize on it I lose the first character of my terminal prompt line

Instead of
C:\Users\Insomniak
it's
:\Users\Insomniak

Local user mitigation is just to not maximize or do a half screen maximize and then just drag it out.

I think that this is what you were mentioning but if that isn't the case let me know and I'll file a separate issue.

@Insomniak47 commented on GitHub (Jul 13, 2019): Just wanted to pop in and confirm that your intuition re: Maximizing on non-primary windows is correct: I've got a portrait mode 1920*1080 monitor and when I maximize on it I lose the first character of my terminal prompt line Instead of `C:\Users\Insomniak ` it's ` :\Users\Insomniak ` Local user mitigation is just to not maximize or do a half screen maximize and then just drag it out. I think that this is what you were mentioning but if that isn't the case let me know and I'll file a separate issue.
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 14, 2019):

That one is known and fixed in the dev build 😄

@DHowett-MSFT commented on GitHub (Jul 14, 2019): That one is known and fixed in the dev build :smile:
Author
Owner

@ghost commented on GitHub (Nov 26, 2019):

:tada:This issue was addressed in #3394, which has now been successfully released as Windows Terminal Preview v0.7.3291.0.🎉

Handy links:

@ghost commented on GitHub (Nov 26, 2019): :tada:This issue was addressed in #3394, which has now been successfully released as `Windows Terminal Preview v0.7.3291.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.7.3291.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2669