reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit de8b9ee0e0c6b5064db2f0a12b55c3ae4f79d938
parent ec9a4f41223fe7e9bbd39655269fe1e89d9b8b09
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Thu,  5 Jan 2017 00:06:38 -0500

dialog: consider the screen size when centering windows on macOS also

Diffstat:
Msrc/dialog.cpp | 27+++++++++++++++++----------
Msrc/dialog.hpp | 1+
2 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/src/dialog.cpp b/src/dialog.cpp @@ -218,19 +218,21 @@ void Dialog::center() GetWindowRect(m_parent, &parentRect); #ifdef _WIN32 - // limit the centering to the monitor containing most of the parent window HMONITOR monitor = MonitorFromWindow(m_parent, MONITOR_DEFAULTTONEAREST); MONITORINFO minfo{sizeof(MONITORINFO)}; - - if(GetMonitorInfo(monitor, &minfo)) { - parentRect.left = max(parentRect.left, minfo.rcWork.left); - parentRect.top = max(parentRect.top, minfo.rcWork.top); - - parentRect.right = min(parentRect.right, minfo.rcWork.right); - parentRect.bottom = min(parentRect.bottom, minfo.rcWork.bottom); - } + GetMonitorInfo(monitor, &minfo); + RECT &screenRect = minfo.rcWork; +#else + RECT screenRect; + SWELL_GetViewPort(&screenRect, &dialogRect, false); #endif + // limit the centering to the monitor containing most of the parent window + parentRect.left = max(parentRect.left, screenRect.left); + parentRect.top = max(parentRect.top, screenRect.top); + parentRect.right = min(parentRect.right, screenRect.right); + parentRect.bottom = min(parentRect.bottom, screenRect.bottom); + const int parentWidth = parentRect.right - parentRect.left; const int dialogWidth = dialogRect.right - dialogRect.left; int left = (parentWidth - dialogWidth) / 2; @@ -249,7 +251,7 @@ void Dialog::center() top += verticalBias; // according to SWELL, top means bottom. #endif - boundedMove(left, top); + move(left, top); } void Dialog::boundedMove(int x, int y) @@ -279,6 +281,11 @@ void Dialog::boundedMove(int x, int y) x = min(max(viewportX, x), viewportWidth - width - abs(viewportX)); y = min(max(viewportY, y), viewportHeight - height - abs(viewportY)); + move(x, y); +} + +void Dialog::move(const int x, const int y) +{ SetWindowPos(m_handle, nullptr, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE); } diff --git a/src/dialog.hpp b/src/dialog.hpp @@ -96,6 +96,7 @@ public: void close(INT_PTR = 0); void center(); + void move(int x, int y); void boundedMove(int x, int y); bool hasFocus() const; void setFocus();