Skip to content

Commit

Permalink
Merge pull request #6489 from Jjagg/sdl-weird-close
Browse files Browse the repository at this point in the history
Only handle MG window and exit when it's closed
  • Loading branch information
harry-cpp authored Nov 14, 2018
2 parents db45571 + 9a5587f commit d955c33
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 4 additions & 0 deletions MonoGame.Framework/SDL/SDL2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ public static IntPtr Create(string title, int x, int y, int w, int h, int flags)
public delegate void d_sdl_destroywindow(IntPtr window);
public static d_sdl_destroywindow Destroy = FuncLoader.LoadFunction<d_sdl_destroywindow>(NativeLibrary, "SDL_DestroyWindow");

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate uint d_sdl_getwindowid(IntPtr window);
public static d_sdl_getwindowid GetWindowId = FuncLoader.LoadFunction<d_sdl_getwindowid>(NativeLibrary, "SDL_GetWindowID");

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate int d_sdl_getwindowdisplayindex(IntPtr window);
private static d_sdl_getwindowdisplayindex SDL_GetWindowDisplayIndex = FuncLoader.LoadFunction<d_sdl_getwindowdisplayindex>(NativeLibrary, "SDL_GetWindowDisplayIndex");
Expand Down
22 changes: 13 additions & 9 deletions MonoGame.Framework/SDL/SDLGamePlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,19 @@ private void SdlRunLoop()
}
else if (ev.Type == Sdl.EventType.WindowEvent)
{
if (ev.Window.EventID == Sdl.Window.EventId.Resized || ev.Window.EventID == Sdl.Window.EventId.SizeChanged)
_view.ClientResize(ev.Window.Data1, ev.Window.Data2);
else if (ev.Window.EventID == Sdl.Window.EventId.FocusGained)
IsActive = true;
else if (ev.Window.EventID == Sdl.Window.EventId.FocusLost)
IsActive = false;
else if (ev.Window.EventID == Sdl.Window.EventId.Moved)
_view.Moved();
if (ev.Window.WindowID == _view.Id)
{
if (ev.Window.EventID == Sdl.Window.EventId.Resized || ev.Window.EventID == Sdl.Window.EventId.SizeChanged)
_view.ClientResize(ev.Window.Data1, ev.Window.Data2);
else if (ev.Window.EventID == Sdl.Window.EventId.FocusGained)
IsActive = true;
else if (ev.Window.EventID == Sdl.Window.EventId.FocusLost)
IsActive = false;
else if (ev.Window.EventID == Sdl.Window.EventId.Moved)
_view.Moved();
else if (ev.Window.EventID == Sdl.Window.EventId.Close)
_isExiting++;
}
}
}
}
Expand Down Expand Up @@ -230,7 +235,6 @@ public override void Present()
{
if (Game.GraphicsDevice != null)
Game.GraphicsDevice.Present();

}

protected override void Dispose(bool disposing)
Expand Down
3 changes: 3 additions & 0 deletions MonoGame.Framework/SDL/SDLGameWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public override bool IsBorderless
}

public static GameWindow Instance;
public uint? Id;
public bool IsFullScreen;

internal readonly Game _game;
Expand Down Expand Up @@ -155,6 +156,8 @@ internal void CreateWindow()
_handle = Sdl.Window.Create(AssemblyHelper.GetDefaultWindowTitle(),
winx, winy, _width, _height, initflags);

Id = Sdl.Window.GetWindowId(_handle);

if (_icon != IntPtr.Zero)
Sdl.Window.SetIcon(_handle, _icon);

Expand Down

0 comments on commit d955c33

Please sign in to comment.