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

Open
opened 2026-01-30 23:01:48 +00:00 by claunia · 0 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#2666