diff --git a/DDrawCompat/DDraw/DirectDraw.cpp b/DDrawCompat/DDraw/DirectDraw.cpp index a04ff04..f53cad4 100644 --- a/DDrawCompat/DDraw/DirectDraw.cpp +++ b/DDrawCompat/DDraw/DirectDraw.cpp @@ -149,6 +149,10 @@ namespace if (wasFullscreen != isFullscreen) { tagSurface->setFullscreenWindow(isFullscreen ? hWnd : nullptr); + if (!isFullscreen) + { + DDraw::PrimarySurface::setWindowedCooperativeLevel(); + } } } } diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp index 02215bf..da1835a 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.cpp @@ -299,6 +299,29 @@ namespace DDraw } } + void PrimarySurface::setWindowedCooperativeLevel() + { + LOG_FUNC("PrimarySurface::setWindowedCooperativeLevel"); + if (!g_primarySurface) + { + return; + } + + RealPrimarySurface::restore(); + + if (FAILED(g_primarySurface->IsLost(g_primarySurface))) + { + return; + } + + auto surface = Surface::getSurface(*g_primarySurface); + if (surface) + { + onLost(); + surface->restore(); + } + } + void PrimarySurface::updateFrontResource() { g_frontResource = DirectDrawSurface::getDriverResourceHandle(*g_primarySurface); diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurface.h b/DDrawCompat/DDraw/Surfaces/PrimarySurface.h index 5809af1..e825b22 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurface.h +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurface.h @@ -29,6 +29,7 @@ namespace DDraw static DWORD getOrigCaps(); static void onLost(); static void setAsRenderTarget(); + static void setWindowedCooperativeLevel(); static void updatePalette(); template diff --git a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp index eb74025..826339a 100644 --- a/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp +++ b/DDrawCompat/DDraw/Surfaces/PrimarySurfaceImpl.cpp @@ -153,6 +153,11 @@ namespace DDraw template HRESULT PrimarySurfaceImpl::Flip(TSurface* This, TSurface* lpDDSurfaceTargetOverride, DWORD dwFlags) { + if (!RealPrimarySurface::isFullscreen()) + { + return DDERR_NOEXCLUSIVEMODE; + } + RealPrimarySurface::setUpdateReady(); RealPrimarySurface::flush(); RealPrimarySurface::waitForFlip(m_data->getDDS());