diff --git a/DDrawCompat/D3dDdi/Resource.cpp b/DDrawCompat/D3dDdi/Resource.cpp index a6574bb..b6263df 100644 --- a/DDrawCompat/D3dDdi/Resource.cpp +++ b/DDrawCompat/D3dDdi/Resource.cpp @@ -1412,7 +1412,8 @@ namespace D3dDdi } Gdi::Cursor::setMonitorClipRect(clipRect); - Gdi::Cursor::setEmulated(mi.isEmulated); + DDraw::RealPrimarySurface::setEmulatedCursor(0 != g_presentationRect.left || 0 != g_presentationRect.top || + Rect::getSize(mi.rcEmulated) != Rect::getSize(g_presentationRect)); Gdi::VirtualScreen::setFullscreenMode(m_origData.Flags.MatchGdiPrimary); } else @@ -1421,7 +1422,7 @@ namespace D3dDdi g_presentationRect = {}; Gdi::VirtualScreen::setFullscreenMode(false); - Gdi::Cursor::setEmulated(false); + DDraw::RealPrimarySurface::setEmulatedCursor(false); Gdi::Cursor::setMonitorClipRect({}); } } diff --git a/DDrawCompat/DDraw/RealPrimarySurface.cpp b/DDrawCompat/DDraw/RealPrimarySurface.cpp index ddda5f0..5f30cf1 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.cpp +++ b/DDrawCompat/DDraw/RealPrimarySurface.cpp @@ -58,6 +58,7 @@ namespace DDSURFACEDESC2 g_surfaceDesc = {}; DDraw::IReleaseNotifier g_releaseNotifier(onRelease); + bool g_emulatedCursor = false; bool g_isFullscreen = false; bool g_isExclusiveFullscreen = false; DDraw::Surface* g_lastFlipSurface = nullptr; @@ -478,6 +479,11 @@ namespace } } prevFullscreenWindow = fullscreenWindow; + + if (Gdi::Cursor::isEmulated() != g_emulatedCursor) + { + Gdi::Cursor::setEmulated(g_emulatedCursor); + } } unsigned WINAPI updateThreadProc(LPVOID /*lpParameter*/) @@ -827,6 +833,11 @@ namespace DDraw g_qpcUpdatePresentationWindow = Time::queryPerformanceCounter() + Time::g_qpcFrequency / 5; } + void RealPrimarySurface::setEmulatedCursor(bool emulated) + { + g_emulatedCursor = emulated; + } + HRESULT RealPrimarySurface::setGammaRamp(DDGAMMARAMP* rampData) { DDraw::ScopedThreadLock lock; diff --git a/DDrawCompat/DDraw/RealPrimarySurface.h b/DDrawCompat/DDraw/RealPrimarySurface.h index c053dec..cb41fa1 100644 --- a/DDrawCompat/DDraw/RealPrimarySurface.h +++ b/DDrawCompat/DDraw/RealPrimarySurface.h @@ -29,6 +29,7 @@ namespace DDraw static void scheduleOverlayUpdate(); static void scheduleUpdate(); static void schedulePresentationWindowUpdate(); + static void setEmulatedCursor(bool emulated); static HRESULT setGammaRamp(DDGAMMARAMP* rampData); static void setPresentationWindowTopmost(); static void setUpdateReady(); diff --git a/DDrawCompat/Gdi/User32WndProcs.cpp b/DDrawCompat/Gdi/User32WndProcs.cpp index 8a3c9d7..14f4193 100644 --- a/DDrawCompat/Gdi/User32WndProcs.cpp +++ b/DDrawCompat/Gdi/User32WndProcs.cpp @@ -319,6 +319,11 @@ namespace void fixPopupMenuPosition(WINDOWPOS& wp) { RECT mr = DDraw::PrimarySurface::getMonitorRect(); + if (IsRectEmpty(&mr)) + { + return; + } + if (wp.flags & SWP_NOSIZE) { RECT r = {}; @@ -433,7 +438,7 @@ namespace { LRESULT result = CallWindowProc(origWndProc, hwnd, msg, wParam, lParam); auto& wp = *reinterpret_cast(lParam); - if (Gdi::Cursor::isEmulated() && !(wp.flags & SWP_NOMOVE)) + if (!(wp.flags & SWP_NOMOVE)) { fixPopupMenuPosition(wp); } diff --git a/DDrawCompat/Gdi/WinProc.cpp b/DDrawCompat/Gdi/WinProc.cpp index 75d442a..8624de6 100644 --- a/DDrawCompat/Gdi/WinProc.cpp +++ b/DDrawCompat/Gdi/WinProc.cpp @@ -516,21 +516,23 @@ namespace void onInitMenuPopup(HMENU menu) { - if (Gdi::Cursor::isEmulated()) + RECT mr = DDraw::PrimarySurface::getMonitorRect(); + if (IsRectEmpty(&mr)) { - MENUINFO mi = {}; - mi.cbSize = sizeof(mi); - mi.fMask = MIM_MAXHEIGHT; - GetMenuInfo(menu, &mi); + return; + } - RECT mr = DDraw::PrimarySurface::getMonitorRect(); - UINT maxHeight = mr.bottom - mr.top; - if (0 == mi.cyMax || mi.cyMax > maxHeight) - { - g_menuMaxHeight[menu] = mi.cyMax; - mi.cyMax = maxHeight; - SetMenuInfo(menu, &mi); - } + MENUINFO mi = {}; + mi.cbSize = sizeof(mi); + mi.fMask = MIM_MAXHEIGHT; + GetMenuInfo(menu, &mi); + + UINT maxHeight = mr.bottom - mr.top; + if (0 == mi.cyMax || mi.cyMax > maxHeight) + { + g_menuMaxHeight[menu] = mi.cyMax; + mi.cyMax = maxHeight; + SetMenuInfo(menu, &mi); } }