Screensaver does not start while my unity application is running
While running my unity application, I have noticed that the windows screensaver will not start (Windows 8, windows 10).
During my investigation, I've noticed that windows screensaver behavior seems to vary based on content. For example, if I'm in google chrome on a regular google search tab "https://www.google.com/", the windows screensaver will start. However, if I am on a google chrome tab viewing the site "https://imgur.com/" the screensaver does not start.
I have been able to work around this issue by removing focus from my application when I suspect it is not in use:
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetForegroundWindow(int hwnd);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int GetDesktopWindow();
private void DeFocusWindowToAllowScreensaver()
{
SetForegroundWindow(GetDesktopWindow());
}
Although this approach seems to work, I would much rather find a direct solution, for example somehow labeling my program as a type of media that windows will feel comfortable starting a screensaver over.
Thank you for any advice!
EDIT:
I found this article https://www.codeproject.com/Articles/17067/Controlling-The-Screen-Saver-With-C Which shows how you can STOP a screensaver, and get information about the screensaver,
and I found this answer https://stackoverflow.com/a/35186130 that shows how to start a screensaver manually. Unfortunately, the latter worked in the Unity editor but it does not seem to work in full screen. So I am still looking for a way to simply set my program as a screensaver allowing application somehow, or prevent whatever signals that are interrupting the screensaver's idle timer.