diff options
author | Underground78 <underground78@users.sourceforge.net> | 2015-08-07 00:11:02 +0300 |
---|---|---|
committer | Underground78 <underground78@users.sourceforge.net> | 2015-08-08 23:06:05 +0300 |
commit | 06687e123ee11eea90c0858da153dedef794f0b6 (patch) | |
tree | 9f4318920a682923e1abf1b75a947f47a4b27e56 | |
parent | 05cea41f9d5899a0abd6010cca2315eb6ef01a25 (diff) |
Fix "snap to desktop edge" and "autofit zoom" on Windows 10.
The window has some using invisible borders on Windows 10 which have to be ignored when snapping or auto-fitting the window.
-rw-r--r-- | docs/Changelog.txt | 1 | ||||
-rw-r--r-- | src/DSUtil/SysVersion.cpp | 5 | ||||
-rw-r--r-- | src/DSUtil/SysVersion.h | 1 | ||||
-rw-r--r-- | src/mpc-hc/MainFrm.cpp | 80 | ||||
-rw-r--r-- | src/mpc-hc/MainFrm.h | 1 |
5 files changed, 73 insertions, 15 deletions
diff --git a/docs/Changelog.txt b/docs/Changelog.txt index 3f1e1c252..a86f5f5a3 100644 --- a/docs/Changelog.txt +++ b/docs/Changelog.txt @@ -37,6 +37,7 @@ next version - not released yet Romanian, Russian, Slovak, Spanish, Swedish, Thai, Turkish and Vietnamese translations
! Fix a rare crash when exiting DVB mode
! QuickTime: Fix a crash when using system default renderer
+! Fix "snap to desktop edge" and "autofit zoom" on Windows 10
! Ticket #4086, Logitech LCD: Correctly initialize the volume at start-up
! Ticket #5454, Deleting an item from the playlist sometimes did not work when shuffle mode was enabled
! Ticket #5464, If the main window was minimized while the D3D Fullscreen window was displayed on another screen,
diff --git a/src/DSUtil/SysVersion.cpp b/src/DSUtil/SysVersion.cpp index 40d956b87..6db223293 100644 --- a/src/DSUtil/SysVersion.cpp +++ b/src/DSUtil/SysVersion.cpp @@ -95,6 +95,11 @@ bool SysVersion::Is81OrLater() return (GetVersion() >= 0x0603);
}
+bool SysVersion::Is10OrLater()
+{
+ return (GetVersion() >= 0x0A00);
+}
+
bool SysVersion::Is64Bit()
{
const bool bIs64Bit = InitIs64Bit();
diff --git a/src/DSUtil/SysVersion.h b/src/DSUtil/SysVersion.h index cd970725c..8669abe07 100644 --- a/src/DSUtil/SysVersion.h +++ b/src/DSUtil/SysVersion.h @@ -35,6 +35,7 @@ namespace SysVersion bool Is8();
bool Is8OrLater();
bool Is81OrLater();
+ bool Is10OrLater();
bool Is64Bit();
};
diff --git a/src/mpc-hc/MainFrm.cpp b/src/mpc-hc/MainFrm.cpp index 6df4fdcce..2963b0ac8 100644 --- a/src/mpc-hc/MainFrm.cpp +++ b/src/mpc-hc/MainFrm.cpp @@ -1348,6 +1348,9 @@ void CMainFrame::OnMoving(UINT fwSide, LPRECT pRect) CRect areaRect;
CMonitors::GetNearestMonitor(this).GetWorkAreaRect(areaRect);
+ if (SysVersion::Is10OrLater()) {
+ areaRect.InflateRect(GetInvisibleBorderSize());
+ }
bool bSnapping = false;
@@ -9311,6 +9314,30 @@ void CMainFrame::RestoreDefaultWindowRect() }
}
+CRect CMainFrame::GetInvisibleBorderSize() const
+{
+ CRect invisibleBorders;
+
+ if (SysVersion::Is10OrLater()) {
+ static const WinapiFunc<decltype(DwmGetWindowAttribute)>
+ fnDwmGetWindowAttribute = { "Dwmapi.dll", "DwmGetWindowAttribute" };
+
+ if (fnDwmGetWindowAttribute) {
+ if (SUCCEEDED(fnDwmGetWindowAttribute(GetSafeHwnd(), DWMWA_EXTENDED_FRAME_BOUNDS, &invisibleBorders, sizeof(RECT)))) {
+ CRect windowRect;
+ GetWindowRect(windowRect);
+
+ invisibleBorders.TopLeft() = invisibleBorders.TopLeft() - windowRect.TopLeft();
+ invisibleBorders.BottomRight() = windowRect.BottomRight() - invisibleBorders.BottomRight();
+ } else {
+ ASSERT(false);
+ }
+ }
+ }
+
+ return invisibleBorders;
+}
+
OAFilterState CMainFrame::GetMediaState() const
{
OAFilterState ret = -1;
@@ -9994,6 +10021,12 @@ CSize CMainFrame::GetZoomWindowSize(double dScale) CMonitors::GetNearestMonitor(this).GetWorkAreaRect(workRect);
if (workRect.Width() && workRect.Height()) {
+ // account for invisible borders on Windows 10 by allowing
+ // the window to go out of screen a bit
+ if (SysVersion::Is10OrLater()) {
+ workRect.InflateRect(GetInvisibleBorderSize());
+ }
+
// don't go larger than the current monitor working area and prevent black bars in this case
CSize videoSpaceSize = workRect.Size() - controlsSize - decorationsRect.Size();
@@ -10036,23 +10069,31 @@ CRect CMainFrame::GetZoomWindowRect(const CSize& size) MONITORINFO mi = { sizeof(mi) };
if (GetMonitorInfo(MonitorFromWindow(m_hWnd, MONITOR_DEFAULTTONEAREST), &mi)) {
+ CRect rcWork = mi.rcWork;
+ // account for invisible borders on Windows 10 by allowing
+ // the window to go out of screen a bit
+ if (SysVersion::Is10OrLater()) {
+ rcWork.InflateRect(GetInvisibleBorderSize());
+ }
+
CSize windowSize(size);
// don't go larger than the current monitor working area
- windowSize.cx = std::min<long>(windowSize.cx, (mi.rcWork.right - mi.rcWork.left));
- windowSize.cy = std::min<long>(windowSize.cy, (mi.rcWork.bottom - mi.rcWork.top));
+ windowSize.cx = std::min<long>(windowSize.cx, rcWork.Width());
+ windowSize.cy = std::min<long>(windowSize.cy, rcWork.Height());
- // retain snapping and center the window if we don't remember its position
- if (m_bWasSnapped && ret.left == mi.rcWork.left) {
+ // retain snapping or try not to be move the center of the window
+ // if we don't remember its position
+ if (m_bWasSnapped && ret.left == rcWork.left) {
// do nothing
- } else if (m_bWasSnapped && ret.right == mi.rcWork.right) {
+ } else if (m_bWasSnapped && ret.right == rcWork.right) {
ret.left = ret.right - windowSize.cx;
} else if (!s.fRememberWindowPos) {
ret.left += (ret.right - ret.left) / 2 - windowSize.cx / 2;
}
- if (m_bWasSnapped && ret.top == mi.rcWork.top) {
+ if (m_bWasSnapped && ret.top == rcWork.top) {
// do nothing
- } else if (m_bWasSnapped && ret.bottom == mi.rcWork.bottom) {
+ } else if (m_bWasSnapped && ret.bottom == rcWork.bottom) {
ret.top = ret.bottom - windowSize.cy;
} else if (!s.fRememberWindowPos) {
ret.top += (ret.bottom - ret.top) / 2 - windowSize.cy / 2;
@@ -10062,17 +10103,17 @@ CRect CMainFrame::GetZoomWindowRect(const CSize& size) ret.bottom = ret.top + windowSize.cy;
// don't go beyond the current monitor working area
- if (ret.right > mi.rcWork.right) {
- ret.OffsetRect(mi.rcWork.right - ret.right, 0);
+ if (ret.right > rcWork.right) {
+ ret.OffsetRect(rcWork.right - ret.right, 0);
}
- if (ret.left < mi.rcWork.left) {
- ret.OffsetRect(mi.rcWork.left - ret.left, 0);
+ if (ret.left < rcWork.left) {
+ ret.OffsetRect(rcWork.left - ret.left, 0);
}
- if (ret.bottom > mi.rcWork.bottom) {
- ret.OffsetRect(0, mi.rcWork.bottom - ret.bottom);
+ if (ret.bottom > rcWork.bottom) {
+ ret.OffsetRect(0, rcWork.bottom - ret.bottom);
}
- if (ret.top < mi.rcWork.top) {
- ret.OffsetRect(0, mi.rcWork.top - ret.top);
+ if (ret.top < rcWork.top) {
+ ret.OffsetRect(0, rcWork.top - ret.top);
}
} else {
ASSERT(FALSE);
@@ -10153,6 +10194,15 @@ double CMainFrame::GetZoomAutoFitScale(bool bLargerOnly) decorationsSize.cx += 2 * ::GetSystemMetrics(SM_CXSIZEFRAME);
// horizontal borders
decorationsSize.cy += 2 * ::GetSystemMetrics(SM_CYSIZEFRAME);
+
+ // account for invisible borders on Windows 10
+ if (SysVersion::Is10OrLater()) {
+ RECT invisibleBorders = GetInvisibleBorderSize();
+
+ decorationsSize.cx -= (invisibleBorders.left + invisibleBorders.right);
+ decorationsSize.cy -= (invisibleBorders.top + invisibleBorders.bottom);
+ }
+
if (!(style & WS_CAPTION)) {
decorationsSize.cx -= 2;
decorationsSize.cy -= 2;
diff --git a/src/mpc-hc/MainFrm.h b/src/mpc-hc/MainFrm.h index c5b05edcb..4f7750936 100644 --- a/src/mpc-hc/MainFrm.h +++ b/src/mpc-hc/MainFrm.h @@ -285,6 +285,7 @@ private: void SetDefaultWindowRect(int iMonitor = 0);
void SetDefaultFullscreenState();
void RestoreDefaultWindowRect();
+ CRect GetInvisibleBorderSize() const;
CSize GetZoomWindowSize(double dScale);
CRect GetZoomWindowRect(const CSize& size);
void ZoomVideoWindow(double dScale = ZOOM_DEFAULT_LEVEL);
|