Skip to content

Commit

Permalink
[PTRun]Detect full-screen games with QUNS_RUNNING_D3D_FULL_SCREEN (#3…
Browse files Browse the repository at this point in the history
…0797)

* Add SHQueryUserNotificationState to NativeMethods

* Check for QUNS_RUNNING_D3D_FULL_SCREEN in IsWindowFullscreen

The current test for whether a window is full-screen (i.e. a movie or a game) is a bit of a heuristic. In certain cases however, we can *know* that a window is full-screen. Check that case first, then proceed with the existing logic

* Make spellchecker happier
  • Loading branch information
anaisbetts authored Jan 17, 2024
1 parent 6522079 commit 0be120d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/modules/launcher/PowerLauncher/Helper/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ internal static class NativeMethods
[DllImport("user32.DLL", CharSet = CharSet.Unicode)]
internal static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

[DllImport("shell32.dll")]
public static extern int SHQueryUserNotificationState(out UserNotificationState state);

public static string[] CommandLineToArgvW(string cmdLine)
{
IntPtr argv = IntPtr.Zero;
Expand Down Expand Up @@ -242,4 +245,15 @@ internal enum WM
TRAYMOUSEMESSAGE = 0x800, // WM_USER + 1024
APP = 0x8000,
}

internal enum UserNotificationState : int
{
QUNS_NOT_PRESENT = 1,
QUNS_BUSY,
QUNS_RUNNING_D3D_FULL_SCREEN,
QUNS_PRESENTATION_MODE,
QUNS_ACCEPTS_NOTIFICATIONS,
QUNS_QUIET_TIME,
QUNS_APP,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,15 @@ internal enum INPUTTYPE : uint

public static bool IsWindowFullscreen()
{
// First, check to see if a game is fullscreen, if so, we definitely have
// a full-screen window
UserNotificationState state;
if (Marshal.GetExceptionForHR(NativeMethods.SHQueryUserNotificationState(out state)) == null &&
state == UserNotificationState.QUNS_RUNNING_D3D_FULL_SCREEN)
{
return true;
}

// get current active window
IntPtr hWnd = NativeMethods.GetForegroundWindow();

Expand Down

0 comments on commit 0be120d

Please sign in to comment.