From: Zebediah Figura zfigura@codeweavers.com
This matches Windows behaviour at least as of Windows 7.
Signed-off-by: Zebediah Figura zfigura@codeweavers.com Signed-off-by: Henri Verbeet hverbeet@codeweavers.com --- This supersedes patch 167864.
dlls/wined3d/device.c | 10 ++++++++++ dlls/wined3d/swapchain.c | 11 +++++++++++ dlls/wined3d/wined3d_private.h | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 4a6b005bf1d..6b4b07975a9 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -912,6 +912,8 @@ static void destroy_default_samplers(struct wined3d_device *device, struct wined
HRESULT CDECL wined3d_device_acquire_focus_window(struct wined3d_device *device, HWND window) { + unsigned int screensaver_active; + TRACE("device %p, window %p.\n", device, window);
if (!wined3d_register_window(NULL, window, device, 0)) @@ -922,6 +924,9 @@ HRESULT CDECL wined3d_device_acquire_focus_window(struct wined3d_device *device,
InterlockedExchangePointer((void **)&device->focus_window, window); SetWindowPos(window, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); + SystemParametersInfoW(SPI_GETSCREENSAVEACTIVE, 0, &screensaver_active, 0); + if ((device->restore_screensaver = !!screensaver_active)) + SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0);
return WINED3D_OK; } @@ -932,6 +937,11 @@ void CDECL wined3d_device_release_focus_window(struct wined3d_device *device)
if (device->focus_window) wined3d_unregister_window(device->focus_window); InterlockedExchangePointer((void **)&device->focus_window, NULL); + if (device->restore_screensaver) + { + SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, TRUE, NULL, 0); + device->restore_screensaver = FALSE; + } }
static void device_init_swapchain_state(struct wined3d_device *device, struct wined3d_swapchain *swapchain) diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c index 7d73dd1eee5..4aa56bb3f57 100644 --- a/dlls/wined3d/swapchain.c +++ b/dlls/wined3d/swapchain.c @@ -1172,6 +1172,7 @@ void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activa { struct wined3d_device *device = swapchain->device; HWND window = swapchain->state.device_window; + unsigned int screensaver_active; BOOL focus_messages, filter;
/* This code is not protected by the wined3d mutex, so it may run while @@ -1184,6 +1185,10 @@ void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activa
if (activate) { + SystemParametersInfoW(SPI_GETSCREENSAVEACTIVE, 0, &screensaver_active, 0); + if ((device->restore_screensaver = !!screensaver_active)) + SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, FALSE, NULL, 0); + if (!(device->create_parms.flags & WINED3DCREATE_NOWINDOWCHANGES)) { /* The d3d versions do not agree on the exact messages here. D3d8 restores @@ -1209,6 +1214,12 @@ void wined3d_swapchain_activate(struct wined3d_swapchain *swapchain, BOOL activa } else { + if (device->restore_screensaver) + { + SystemParametersInfoW(SPI_SETSCREENSAVEACTIVE, TRUE, NULL, 0); + device->restore_screensaver = FALSE; + } + if (FAILED(wined3d_set_adapter_display_mode(device->wined3d, device->adapter->ordinal, NULL))) ERR("Failed to set display mode.\n"); diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index c7d9cd74258..f7fd136adae 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3180,7 +3180,8 @@ struct wined3d_device BYTE d3d_initialized : 1; BYTE inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */ BYTE softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */ - BYTE padding : 4; + BYTE restore_screensaver : 1; + BYTE padding : 3;
unsigned char surface_alignment; /* Line Alignment of surfaces */