Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix active state event on startup #8123

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion MonoGame.Framework/Platform/SDL/SDL2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,33 @@ public struct SDL_SysWMinfo
public IntPtr window;
}

[Flags]
public enum Flags : uint
{
Fullscreen = 0x00000001,
FullsceenDesktop = (Fullscreen | 0x00001000),
OpenGL = 0x00000002,
Vulkan = 0x10000000,
Metal = 0x10000000,
Shown = 0x00000004,
Hidden = 0x00000008,
Borderless = 0x00000010,
Resizable = 0x00000020,
Minimized = 0x00000040,
Maximized = 0x00000080,
InputGrabbed = 0x00000100,
InputFocus = 0x00000200,
MouseFocus = 0x00000400,
Foreign = 0x00000800,
AllowHighDPI = 0x00002000,
MouseCapture = 0x00004000,
AlwaysOnTop = 0x00008000,
SkipTaskbar = 0x00010000,
Utility = 0x00020000,
Tooltip = 0x00040000,
PopupMenu = 0x00080000,
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr d_sdl_createwindow(string title, int x, int y, int w, int h, int flags);
private static d_sdl_createwindow SDL_CreateWindow = FuncLoader.LoadFunction<d_sdl_createwindow>(NativeLibrary, "SDL_CreateWindow");
Expand Down Expand Up @@ -419,7 +446,7 @@ public static int GetDisplayIndex(IntPtr window)
}

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int d_sdl_getwindowflags(IntPtr window);
public delegate Flags d_sdl_getwindowflags(IntPtr window);
public static d_sdl_getwindowflags GetWindowFlags = FuncLoader.LoadFunction<d_sdl_getwindowflags>(NativeLibrary, "SDL_GetWindowFlags");

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
Expand Down
3 changes: 3 additions & 0 deletions MonoGame.Framework/Platform/SDL/SDLGamePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ public override void RunLoop()
{
Sdl.Window.Show(Window.Handle);

// defaulting active state in case the event pump misses the startup state
IsActive = Sdl.Window.GetWindowFlags(Window.Handle).HasFlag(Sdl.Window.Flags.InputFocus);

while (true)
{
SdlRunLoop();
Expand Down
3 changes: 3 additions & 0 deletions MonoGame.Framework/Platform/Windows/WinFormsGameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ internal WinFormsGameWindow(WinFormsGamePlatform platform)
_resizeTickTimer = new System.Timers.Timer(1) { SynchronizingObject = Form, AutoReset = false };
_resizeTickTimer.Elapsed += OnResizeTick;

// defaulting active state in case the event pump misses the startup state
_platform.IsActive = System.Windows.Forms.Form.ActiveForm == Form;

Form.Activated += OnActivated;
Form.Deactivate += OnDeactivate;
Form.Resize += OnResize;
Expand Down